jQuery检查Ajax发布成功
我如何定义ajax $ .post的成功和失败功能?
how do i define the success and failure function of an ajax $.post?
文档在此处: http ://docs.jquery.com/Ajax/jQuery.ajax
但是,总而言之,ajax调用需要很多选择.您要寻找的是错误和成功.
But, to summarize, the ajax call takes a bunch of options. the ones you are looking for are error and success.
您会这样称呼它:
$.ajax({
url: 'mypage.html',
success: function(){
alert('success');
},
error: function(){
alert('failure');
}
});
我已经展示了成功和错误函数不带参数,但是它们可以接收参数.
I have shown the success and error function taking no arguments, but they can receive arguments.
错误函数可以采用三个参数:XMLHttpRequest,textStatus和errorThrown.
The error function can take three arguments: XMLHttpRequest, textStatus, and errorThrown.
成功函数可以使用两个参数:data和textStatus.您请求的页面将在data参数中.
The success function can take two arguments: data and textStatus. The page you requested will be in the data argument.