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