.then()
reference:
http://www.html-js.com/article/Study-JavaScript-jQuery-Deferred-and-promise-every-day
1.5版本之后,$.ajax()的返回对象实现了CommonJS的Promises/A接口。它包含了很多的内容。CommonJS标准定义了一系列通用的独立的接口。Promises/A+是其中的一个。它带来的好处不仅仅体现在jQuery中。例如,如果你编写Node.js代码,你也可能就经常需要用到这个接口。这是一件非常棒的事情。
使用Promises处理回调函数和前面的例子有所不同:
var promise = $.ajax({
url: "/myServerScript"
});
promise.done(mySuccessFunction);
promise.fail(myErrorFunction);
你也可以在一个then()函数中将done()和fail()函数合并起来。我们可以将上边的代码重写为以下形式:
var promise = $.ajax({
url: "/myServerScript"
});
promise.then(mySuccessFunction,myErrorFunction);
随机推荐
- JavaScript点击按钮显示 确认对话框
//JavaScript点击按钮显示确认对话框 <html xmlns="http://www.w3.org/1999/xhtml"> <head> < ...
- openssl 创建证书的总结和注意事项
1.该文章从网上看了好多博客,并经过实践形成.环境为ubuntu12和ubuntu14 "========================================大纲提要和注意事项= ...
- VS创建、安装、调试 windows服务(windows service)
1.创建 windows服务 项目 文件 -> 新建项目 -> 已安装的模板 -> Visual C# -> windows ,在右侧窗口选择"windows 服 ...
- emacs 中使用git diff命令行
在shell中执行git diff命令,常常会看到例如以下警告信息: terminal is not fully functional 事实上非常easy,配置一下就可以. git config -- ...
- android studio - 导入工程报错[Plugin with id 'com.android.application' not found]
出错现象: 大概意思是找不到:com.android.application 插件,以上现象对于初学者来说会经常碰到,下面分析下产生的原因. 原因分析 首先来看看导入后的工程结构: 对于此工程结构,是 ...
- python-hanoi
#!/usr/bin/env python #-*- coding:utf-8 -*- ############################ #File Name: hanoi.py #Autho ...
- Django-model进阶(中介模型,查询优化,extra,整体插入)
QuerySet 可切片 使用Python 的切片语法来限制查询集记录的数目 .它等同于SQL 的LIMIT 和OFFSET 子句. ? 1 >>> Entry.objects.al ...
- tensorflow之损失函数
#coding:utf-8 __author__ = 'similarface' import tensorflow as tf sess=tf.Session() #max(features, 0) ...
- LNK2019: 无法解析的外部符号(函数实现没有加namespace前缀导致)
问题描述: 在A.h中,我写了如下函数 namespace XXX { void func(); } 在A.cpp中,我写了如下实现 #include "A.h" using na ...
- HTML5坦克大战(2)绘制坦克复习
html代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head&g ...