0

我有这个表格,它附加在一个 div 的点击上

$('#div').click(function(){
   $('#div').load('form.php');
});

这是附加的表格

    <form id="addpic" name="addpic" method="post" enctype="multipart/form-data" action="docupload.php">
      <input type="file" name="mfoni" id="upper1" style="height:10px; width:100px; cursor:hand;" />
      <input type="hidden" name="user" value="<?php echo $id; ?>" id="user" />
   </form> 

现在我想提交表单而不刷新页面或使用下面的代码重定向

$("input#upper1").live('change', function(){
       alert("gone");
       // works up to this point
       $("form#addpic").ajaxForm({
         target: '#loading'
      }).submit();
    })

这可以达到警报('gone')点并且它停止请治愈我

4

1 回答 1

1

看起来您在外部 JS 文件引用下方缺少

http://malsup.github.com/jquery.form.js

另一件事是您需要使用.on()而不是使用.live(). 由于live()方法在 jQuery 1.7 中已被弃用。

您无需使用ajaxForm()and .submit()。只需使用ajaxSubmit().

JS代码:

$("input#upper1").on('change', function(){
    alert("gone");
    $("form#addpic").ajaxSubmit({
        type: "post",
        success: function() {
            alert("Processed");
        },
        complete: function() {
            alert("File upload is completed");
        }
    });
});

参考现场演示

于 2013-10-26T08:36:39.780 回答