ajax发送多个跨域请求回调不混乱

 1     var count = 0;
 2     var codes = "";
 4     function refreshCache(urls){
 5         try {
 6             var url = urls.split(",");
 7             if(url.length <=0){
 8                 alert("刷新失败,请配置刷新地址!");
 9                 return;
10             }
11             count = 0;
12             refesh(url);
13        }catch(err){
14            alert("请求失败。");  
15        }
16     } 
17 
18  function refesh(url){
19         var u = url[count];
20         console.log("第"+count+"个"+u);
21         $.ajax({
22             url : u,
23             type : 'POST',
24             dataType: "jsonp",
25             timeout: 2000,
26             cache:false,
27             async:false,
28             jsonpCallback: "jsonpcallback",
29             success : function(data, status, xhr) {
30                 console.log(u+"回调被执行了... 参数为:"+data);
31                 if(data == '0000'){
32                     console.log(u+"回调执行成功");
33                     count++;
34                     if(count <20 && count < url.length){
35                         refesh(url);
36                     }
37                 }else{
38                     console.log(u+"回调执行失败");
39                     alert("刷新失败,请稍后再试");
40                 }
41             },
42             error : function(xhr, error, exception) {  
43                 alert("请求失败。");  
44             }
45         });
46   }
原文地址:https://www.cnblogs.com/yanlong300/p/7234554.html