`
jsczxy2
  • 浏览: 1255461 次
  • 性别: Icon_minigender_1
  • 来自: 常州
文章分类
社区版块
存档分类
最新评论

JQuery when

阅读更多

首先可以总结一下when的作用:

使用jQuery中的when实现多个AJAX请求对应单个回调

 

 

jQuery.when(deferreds)

参数deferreds,一个或多个延时对象或JS对象,我们初略的认为它就是一个或多个异步请求。

例如:

 

[javascript] view plaincopy
 
  1. $.when($.ajax("page1.php"), $.ajax("page2.php"))  

 

when()函数常常和done()函数、fail()函数、then()函数联合使用:
done(Function func) - 当deferreds中的处理都完成的时候执行Function回调函数
fail(Function func) - 当deferreds中有一个处理失败的时候执行Function回调函数
then(Function func1,Function func2)- 结合了done和fail函数,当都成功执行func1,当有一个失败执行func2

 

Example:

 

[javascript] view plaincopy
 
  1. var whenResult = $.when($.ajax("page1.php"), $.ajax("page2.php"));  
  2. whenResult.done(function(a1,a2){  
  3. //函数内容略  
  4. //a1和a2俩参数是when函数中两个ajax请求的相关jqXHR对象  
  5. });  
  6. whenResult.fail(function(){  
  7. //函数内容略  
  8. })  
  9. whenResult.then(successFunc,failureFunc);  
分享到:
评论

相关推荐

    Jquery $when done then的用法详解

    对于$.ajax请求来说,如果层级比较多,程序看起来会比较乱,而为了解决这种问题,才有了$when…done…fail…then的封装,它将$.ajax这嵌套结构转成了顺序平行的结果,向下面的$.ajax写法,看起来很乱 $.ajax({ url...

    [jQuery.UI.1.7.jQuery用户界面库].文字版.pdf

    We already have a basic working knowledge of the components when we add a new component because of the consistency in how we implement the different components that make up the library. Therefore, we ...

    Learning jQuery 3 - Fifth Edition

    Use selectors in a variety of ways to get anything you want from a page when you need it Master events to bring your web pages to life Add flair to your actions with a variety of different animation ...

    jQuery.in.Action.3rd.Edition.161729207

    Chapter 12 When jQuery is not enough... plugins to the rescue! Chapter 13 Avoiding the callback hell with Deferred Chapter 14 Unit testing with QUnit Chapter 15 How jQuery fits into large projects ...

    jQuery UI Cookbook (pdf + ePub)

    jQuery UI Cookbook(2013.7) Adam ...Explore coding conventions that work best when writing jQuery UI code Learn about unique perspectives on approaches to widget development – maintainability matters

    jquery操作asp.net中GridView方法

    Highlight GridView Rows when Checkbox is checked using jQuery Highlight Negative value columns in ASP.NET GridView using jQuery Searching and Filtering Related How to loop through all grid ...

    jQuery.XDomainRequest.js

    Implements automatic *Cross Origin Resource Sharing* support using the `XDomainRequest` object for IE8 and IE9 when using the [$.ajax](http://api.jquery.com/jQuery.ajax/) function in jQuery 1.5+. ...

    jQuery 1.4 Animation Techniques

    When combined with color and class animations and custom easings that jQuery UI provides, there are even more ways to create animations. A good rule of thumb for using animations is to use slides ...

    jQuery 1.5 API 中文版

    def.when(deferreds)1.5+ Traversing Filtering $.eq( index ) $.first( ) $.last( ) $.has( selector ), .has( element ) $.filter( selector ), .filter( fn(index) ) bool.is( selector ) $.map( fn(index, ...

    jquery电子文档chm

    Whenever a matched element is clicked, the first specified function is fired, when clicked again, the second is fired. All subsequent clicks continue to rotate through the two functions. Use unbind(...

    Beyond jQuery(Apress,2016)

    Many web developers don’t seem to know exactly when they need to use jQuery, and when they don’t – it has become a standard step for many when setting up a new library or web application....

    Beyond.jQuery.1484222342

    Many web developers don't seem to know exactly when they need to use jQuery, and when they don't - it has become a standard step for many when setting up a new library or web application. But relying...

    jQuery in Action 第三版 2016 英

    Thanks to jQuery, no one remembers the bad old days when programmers manually managed browser inconsistencies, CSS selectors support, and DOM navigation, and when every animation was a frustrating ...

    Smashing jQuery.pdf

    jQuery has become a part of my everyday routine in Web design and development, so when Wiley approached me about writing a book on jQuery, I was thrilled. jQuery has opened up a world of possibility...

    autoSave - a jQuery plugin

    Auto-Save your content when editing in HTML input and textarea DOM element. http://geniuscarrier.com/autosave-a-jquery-plugin/

    jQuery最新1.4.4精简版+1.4中文手册

    (Bug) Fixed an issue where host and protocol were not compared case-insensitively when determining whether anAJAXrequest was local or remote (#6908) (Bug) Fixed an issue where the “clone” variable ...

    jquery3.2.1版本

    jquery3.2.1的min版,开发版,地图都含有 jQuery3.X特性: 1. 移除旧的IE工作区 2.jQuery 3.0运行在Strict Mode下 ...8. jQuery.when()对于多种参数的不同解读 9. 新的显示/隐藏逻辑 10. 对于防止XSS攻击的额外保护

    jquery blockUI Version 2.39

    jQuery blockUI plugin Version 2.39 (23-MAY-2011) Demos: $(document).ready(function() { $('#demo1').click(function() { $.blockUI({ message: $('#loginForm') }); setTimeout($.unblockUI, 2000); ...

Global site tag (gtag.js) - Google Analytics