Jquery promise
2014-04-22 18:13
295 查看
Jquery Promis
Success =========>>> done
Fail =========>>> fail
Features:
1.support the "Chain" Call Back
$.ajax("test.html")
.done(function(){ alert("S1!");} )
.fail(function(){ alert("F1"); } )
.done(function(){ alert("S2");} );
-------If success, alert("S1") then alert("S2")
1.support mutiple call point to one Call Back
$.when($.ajax("test1.html"), $.ajax("test2.html"))
.done(function(){ alert("哈哈,成功了!"); })
.fail(function(){ alert("出错啦!"); });
[b]-------Once two ajax call both are success ,then call done(),either call fail()[/b]
3.Three status for the deferred object
要说清楚这个问题,就要引入一个新概念"执行状态"。jQuery规定,deferred对象有三种执行状态----未完成,已完成和已失败。如果执行状态是"已完成"(resolved),deferred对象立刻调用done()方法指定的回调函数;如果执行状态是"已失败",调用fail()方法指定的回调函数;如果执行状态是"未完成",则继续等待,或者调用progress()方法指定的回调函数(jQuery1.7版本添加)。
4.deferred 'then','always'
to glue 'Done' and 'Fail',use 'then' function
$.when($.ajax( "/main.php" ))
.then(successFunc, failureFunc ); OR .then(successFunc);
to always execute function,use 'always'
$.ajax( "test.html" )
.always( function() { alert("已执行!");} );
http://www.infoq.com/cn/news/2011/09/js-promise http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html
Success =========>>> done
Fail =========>>> fail
Features:
1.support the "Chain" Call Back
$.ajax("test.html")
.done(function(){ alert("S1!");} )
.fail(function(){ alert("F1"); } )
.done(function(){ alert("S2");} );
-------If success, alert("S1") then alert("S2")
1.support mutiple call point to one Call Back
$.when($.ajax("test1.html"), $.ajax("test2.html"))
.done(function(){ alert("哈哈,成功了!"); })
.fail(function(){ alert("出错啦!"); });
[b]-------Once two ajax call both are success ,then call done(),either call fail()[/b]
3.Three status for the deferred object
要说清楚这个问题,就要引入一个新概念"执行状态"。jQuery规定,deferred对象有三种执行状态----未完成,已完成和已失败。如果执行状态是"已完成"(resolved),deferred对象立刻调用done()方法指定的回调函数;如果执行状态是"已失败",调用fail()方法指定的回调函数;如果执行状态是"未完成",则继续等待,或者调用progress()方法指定的回调函数(jQuery1.7版本添加)。
4.deferred 'then','always'
to glue 'Done' and 'Fail',use 'then' function
$.when($.ajax( "/main.php" ))
.then(successFunc, failureFunc ); OR .then(successFunc);
to always execute function,use 'always'
$.ajax( "test.html" )
.always( function() { alert("已执行!");} );
http://www.infoq.com/cn/news/2011/09/js-promise http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html
相关文章推荐
- 解决jquery$命名符和其它框架的冲突问题
- jQuery 学习系列笔记(二)
- 移动Web框架:jQuery Mobile VS Sencha Touch
- jQuery Validation范例
- jQuery 之父:每天写代码
- jQuery的编码标准和最佳实践
- 《锋利的jQuery》随笔(一)
- jquery 设置checkbox全选 全不选
- jquery ajax(5)form表单序列化
- 抛弃jQuery 深入原生的JavaScript
- jquery ajax跨域取数据
- css3和jquery实现自定义checkbox和radiobox组件
- jQuery实现的全选、反选和不选功能
- jquery.scrollLoading-min.js实现图片延迟加载
- JQuery实现的简洁Flash幻灯渐变效果
- jQueryUI日期显示
- Jquery表格变色 复选框全选,反选
- 解决JQuery EasyUI 加载两次url的问题
- Jquery-UI实现弹出框样式
- Jquery实现复制内容到粘贴板