【问题标题】:How to use jQuery Form Plugin when sending form with live实时发送表单时如何使用jQuery表单插件
【发布时间】:2012-04-10 15:53:07
【问题描述】:

插件: http://www.malsup.com/jquery/form/#ajaxSubmit

代码:

$( 'form#form' ).live('submit', function( event ){
     if( this.arquivo )
     {
          var options = { 
               success:    showResponse
          }; 

          // pass options to ajaxForm 
          $( '#form' ).ajaxForm( options );         
          $( '#form' ).ajaxSubmit();

          return false;
     }
});


function showResponse(responseText, statusText, xhr, $form)  {
     alert( responseText );
}

通过提交表单,函数 showResponse 没有被调用。

【问题讨论】:

    标签: jquery ajax


    【解决方案1】:

    尝试使用:

    function showResponse(responseText, statusText, xhr, $form)  {
        alert( responseText );
    }
    var options = {
        success: showResponse
    };
    //   you dont need to say form#form although i would suggest changing ID name
        // if you're using newer jquery, .live is deprecated to .on and .off
    $("#form").on("submit", function(e) {
        $(this).ajaxSubmit(options);
        return false; 
    });
    

    虽然,如果表单不是动态创建的,你最好使用:

    $("#form").ajaxForm(options); 
    

    【讨论】:

    • 表单用ajax插入到页面中。所以我使用的是'live'。我更改了 jQuery 的版本,我正在使用'on',但仍然没有工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 2017-08-07
    • 1970-01-01
    • 2011-11-27
    • 2011-01-04
    • 1970-01-01
    • 2015-05-06
    相关资源
    最近更新 更多