0

插件: 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 不会被调用。

4

1 回答 1

0

尝试使用:

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); 
于 2012-04-10T15:59:17.610 回答