通过这样调用
$.post,您将仅自动传递一个
success handler函数。
如果请求中出现问题,则甚至不会执行此方法。
要拥有更多控制权,请
$.ajax()直接使用或传递失败处理程序。看起来像
$.post("page.php", {data: stuff}, function(data, status) { // we're fine here}).fail(function(err, status) { // something went wrong, check err and status});使用相同的东西
.ajax():
$.ajax({ type: 'POST', url: 'page.php', data: stuff, success: function( data ) { }, error: function(xhr, status, error) { // check status && error }, dataType: 'text'});您甚至可以将更多的ajax事件处理程序传递给
$.ajax,如
beforeSend修改/读取XHR标头,或
complete使处理程序在请求完成时触发两种方式(错误或不错误)。



