Javascript jQuery在更改输入值时提交表单

Javascript jQuery在更改输入值时提交表单,javascript,php,jquery,jqueryform,Javascript,Php,Jquery,Jqueryform,我使用jquery.form插件, 它起作用了,很好 但是当改变输入值。。很好!但将我重定向到uploader.php文件,我不想重定向我,我需要在div.result中获得结果 要理解我,请查看我的代码: HTML 我需要在.result div中回显'done',我不想将我重定向到uploader.php页面。当您更改输入值时,它实际上在做什么?我的意思是它是在提交表格吗?还是只有在单击“提交”按钮时才会发生这种情况 在我看来,你的剧本并没有起到任何作用。它侦听表单元素上的onchange事

我使用jquery.form插件, 它起作用了,很好 但是当改变输入值。。很好!但将我重定向到uploader.php文件,我不想重定向我,我需要在div.result中获得结果

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

HTML


我需要在.result div中回显'done',我不想将我重定向到uploader.php页面。

当您更改输入值时,它实际上在做什么?我的意思是它是在提交表格吗?还是只有在单击“提交”按钮时才会发生这种情况

在我看来,你的剧本并没有起到任何作用。它侦听表单元素上的onchange事件,但根据我的经验,该事件从未在
上触发。因此,您只需提交一个HTML表单,而无需借助脚本

除此之外,出于安全原因,我不确定您是否可以使用脚本提交多部分/表单数据表单。也许我错了,但不管怎样,用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>

老实说,我现在不知道iframe上的onload是否有效,我已经好几年没有尝试过了。否则,请删除
和相应的
,并将它们与动画脚本一起放入uploader.php的输出中。

使用.ajaxSubmit({})


谢谢大家。

由于表单的操作是uploader.php,因此,提交后页面将重定向到uploader.php。因此,您需要更改操作并使用ajax更新div.result。 检查这些链接一次。

除非您单击“提交”按钮,否则我认为不应该发生这种情况。在我的“文件输入”中拖放文件时,我需要提交。当您单击“提交”按钮时,它应该重定向,当您使用
.ajaxForm()
时,它不应该重定向。updloader是表单元素的选择器。文件将指向输入字段。文件选择器不工作:(他想使用jquery.form.js,他的代码已经很好了。可能是他没有包括相关的js。
<?php
    if( isset($_POST['submit']) and $_SERVER['REQUEST_METHOD'] == "POST" ){
        echo 'done!';
    }
?>
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();
            },

        });

    });

});
<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>
jQuery(document).ready(function() {

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

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

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

    });

});