插件: 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。
答案 0 :(得分: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);