jQuery在IE7和8下setInterval失效的问题

原因不在于setInterval,而是IE的缓存造成ajax请求页没有更新的问题。

在请求的url中加入一个随机数参数即可。

 1 var CheckPaied = function (transactionId, ctoken) {
 2     var id;
 3     function querypaied() {
 4         $.ajax({
 5             type: "get",
 6             url: "status.ashx?_=" + generateMixed(10),//加url参数
 7             dataType:"json",
 8             success: function (data, textStatus) {
 9                 if (data.succ && data.qrStatus == "invalid") {
10                     clearInterval(id);
11                     location.href = "result.aspx";
12                     return false;
13                 }
14             },
15             error: function () {
16                 //alert("未知错误!");
17             }
18         });
19         return false;
20     }
21     id=setInterval(querypaied, 3000);
22 }
23 
24 var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
25 function generateMixed(n) {
26     var res = "";
27     for (var i = 0; i < n ; i++) {
28         var id = Math.ceil(Math.random() * 35);
29         res += chars[id];
30     }
31     return res;
32 }

 

posted @ 2016-07-20 18:12  叮*^_^*叮  阅读(1037)  评论(0编辑  收藏  举报