I'm used jquery.form plugin, it's working and good but when change input value.. it's submitted good! but redirect me to my uploader.php file, i don't want redirect me, i need to get result in div.result,

我使用jquery。表单插件,运行良好,但当输入值改变时。这是提交好!但是把我重定向到上传者。php文件,我不想重定向,我需要得到div。result,

to understand me, please look to my code:

要理解我,请查看我的代码:

HTML

HTML

<form id="uploader" action="uploader.php" method="post" enctype="multipart/form-data">
    <input id="file" type="file" name="uploader" value="" draggable="true">
    <input name="submit" type="submit" class="submit" value="Upload">
    <div class="result"></div>
</form>

uploader.php file:

上传。php文件:

<?php
    if( isset($_POST['submit']) and $_SERVER['REQUEST_METHOD'] == "POST" ){
        echo 'done!';
    }
?>

jQuery code:

jQuery代码:

jQuery(document).ready(function() {

    $('#uploader').change(function(){

        $(".result").html('');

        $(".result").html('wait..');

        $("#uploader").ajaxForm({
            target: '.result',
            success: function() 
            {
                $('.result').hide().slideDown('fast');
                $('#uploader')[0].reset();
            },

        });

    });

});

I need to echo 'done' in .result div, i don't want to redirect me to uploader.php page.

我需要在。result div中返回“done”,我不想将我重定向到uploader。php页面。

4 个解决方案

#1


0

Is it actually doing anything when you change the input value? I mean is it submitting the form? Or does that only happen when you click the submit button?

当你改变输入值时,它实际上做了什么吗?是提交表格吗?还是只在单击submit按钮时才会发生?

It seems to me that your script doesn't really do anything. It listens for an onchange event on the form element, but that event, in my experience, is never fired on a <form>. So you just have an HTML form submitting with no aid of script.

在我看来,你的剧本并没有什么作用。它侦听表单元素上的onchange事件,但在我的经验中,该事件从未被触发为

。你只需要提交一个HTML表单,不需要脚本。

On top of that I'm not sure you can submit a multipart/form-data form with script, for security reasons. Maybe I'm wrong about that, but either way, how about using an iframe instead?

最重要的是,出于安全考虑,我不确定是否可以提交带有脚本的多部分/表单数据表单。也许我错了,但是不管怎样,用iframe代替怎么样?

<form id="uploader" action="uploader.php" method="post" enctype="multipart/form-data" target="resultframe">
    <input id="file" type="file" name="uploader" value="" draggable="true">
    <input name="submit" type="submit" class="submit" value="Upload">
    <div class="result"><iframe name="resultframe" onload="$('.result').hide().slideDown('fast');"></iframe></div>
</form>

To be honest I don't know if an onload works on an iframe these days, I haven't tried it in years. Failing that, remove <div class="result"> and the corresponding </div> and put them into the output of uploader.php, along with the animation script.

老实说,我不知道现在iframe上的onload是否能用,我已经很多年没有尝试过了。否则,删除

和相应的

更多相关文章

  1. PHP基础之脚本传参
  2. 如何在表单操作中执行PHP函数?
  3. phpBB3导入帖子的Python脚本
  4. PHP脚本在我的Wordpress文件中。请解码或帮助我删除它。
  5. AJAX调用在JavaScript中运行PHP脚本
  6. 通过Bash脚本语言逃避MYSQL命令行。
  7. 是否可以从另一个sql脚本中的存储过程调用sql脚本?
  8. 程序猿(媛)Shell脚本必备技能之一: 在Linux下如何自动备份mysql
  9. shell脚本中mysqldump的基本使用

随机推荐

  1. PHP面向对象到底是啥?十分钟通俗易懂图文
  2. PHP中的面向对象之构造函数详解
  3. PHP 框架 Hyperf 实现处理超时未支付订单
  4. PHP中的面向对象实践-基本实践案例
  5. PHP 消息队列 Kafka 使用
  6. PHP 并发场景的 3 种解决方案
  7. PHP如何实现简单的Socket
  8. PHP结合AJAX实现搜索提示功能
  9. PHP如何将中文转英文
  10. 深入理解依赖注入是如何实现解耦