.success()和.complete()之间的区别? [英] Difference between .success() and .complete()?

查看:104
本文介绍了.success()和.complete()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从jQuery 1.5开始,所有jQuery的AJAX方法都返回一个jqXHR对象,该对象提供.error().success().complete()方法.

As of jQuery 1.5, all jQuery's AJAX methods return a jqXHR object that provides .error(), .success(), and .complete() methods.

.success().complete()有什么区别?

推荐答案

.success()仅在您的Web服务器使用200 OK HTTP标头响应时才被调用-基本上一切正常.

.success() only gets called if your webserver responds with a 200 OK HTTP header - basically when everything is fine.

但是,无论ajax调用是否成功,.complete()都会始终被调用-也许它输出了错误并返回了错误-.complete()仍将被调用.

However, .complete() will always get called no matter if the ajax call was successful or not - maybe it outputted errors and returned an error - .complete() will still get called.

值得一提的是,.complete()在被调用后会被称为 .success()在被调用之后-对您而言很重要.

It's worth mentioning that .complete() will get called after .success() gets called - if it matters to you.

  • http://api.jquery.com/ajaxComplete/
  • http://api.jquery.com/ajaxSuccess/

这篇关于.success()和.complete()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆