$.when()ÀïÃæµÄ²ÎÊýÊÇwaitº¯Êý£¬Ò²¾ÍÊÇÒ»¸ödeferred¶ÔÏó£¬ËùÒÔ¿ÉÒÔ¼ÌÐøÖ´ÐÐsetTimeoutº¯Êý£¬µÈ´ý5s£¬Ö´ÐÐtasksº¯Êý£¬È»ºóÊÖ¶¯¸Ä±äÁË״̬Ϊ¡°ÒÑÍê³É¡±£¬ËùÒÔÖ´ÐÐdone·½·¨£¬µ¯³ö¡°succeed¡±£¬È»ºóµ¯³ö¡°Ö´ÐÐÍê±Ï£¡¡±¡£
deferred.then()£ºÓÐʱΪÁËÊ¡Ê£¬¿ÉÒÔ°Ñdone()ºÍfail()ºÏÔÚÒ»Æðд£¬Õâ¾ÍÊÇthen()·½·¨¡£
function successFun(){alert("yes");}function failFun(){alert('fail');}$.when($.ajax({url: '/test/json/a.js',dataType:'json',type: 'get'})).then(successFun, failFun);
µ±then·½·¨Ö»ÓÐÒ»¸ö²ÎÊýʱ£¬Ï൱ÓÚdone·½·¨¡£µ±ÓÐÁ½¸ö²ÎÊýʱ£¬µÚÒ»¸öÏ൱ÓÚdone·½·¨£¬µÚ¶þ¸öÏ൱ÓÚfail·½·¨¡£
×ܽá
deferred¶ÔÏóͨ¹ý¶ÔÒ»¸öajaxÇëÇóµÄ¸÷Öֻص÷º¯ÊýµÄ¿ØÖÆ£¬ÈÃjqueryдajax±äµÄ¼òµ¥¡¢ÈÝÒ×ά»¤¡¢ÈÝÒ×À©Õ¹¡£
ÒÔÉÏËùÊöÊÇС±à¸ø´ó¼Ò½éÉܵÄjQueryͨ¹ýdeferred¶ÔÏó¹ÜÀíajaxÒì²½µÄÏà¹Ø֪ʶ£¬Ï£Íû¶Ô´ó¼ÒÓÐËù°ïÖú£¬Èç¹û´ó¼ÒÓÐÈκÎÒÉÎÊÇë¸øÎÒÁôÑÔ£¬Ð¡±à»á¼°Ê±»Ø¸´´ó¼ÒµÄ¡£ÔÚ´ËÒ²·Ç³£¸Ðл´ó¼Ò¶Ô51zixue.netÍøÕ¾µÄÖ§³Ö£¡
¡¡