root 1 year ago
parent
commit
f792655caf
1 changed files with 27 additions and 21 deletions
  1. 27 21
      js/Office/Poll.js

+ 27 - 21
js/Office/Poll.js

@@ -39,29 +39,37 @@ U.MD.O.P.polling = function (params) {
         var text = "";
         var xhr = new XMLHttpRequest();
         var data = "";
+        var time = null;
+        //
+        var fun = function () {
+            clearTimeout(time)
+            text = xhr.responseText;
+            var istrue = true;
+            while (start < text.length && istrue) {
+                end = text.indexOf(delimiter, start);//获取数据的是否已经结束
+                if (end > -1) {
+                    data += text.substring(start, end);
+                    start = end + delimiter.length;
+                    try {
+                        U.MD.O.P.pollingAsyn({ value: JSON.parse(data) })
+                    }
+                    catch (e) {
+                        console.log(e);
+                    }
+                    data = "";
+                }
+                else {
+                    istrue = false;
+                    time = setTimeout(fun, 50);//
+                }
+            }
+        };
         xhr.open("POST", US.SCOKET, true);
         xhr.onreadystatechange = function () {
             //获取数据
             if (xhr.readyState == 3 && xhr.status == 200) {
-                text = xhr.responseText;
-                var istrue = true;
-                while (start < text.length && istrue) {
-                    end = text.indexOf(delimiter, start);//获取数据的是否已经结束
-                    if (end > -1) {
-                        data += text.substring(start, end);
-                        start = end + delimiter.length;
-                        try {
-                            U.MD.O.P.pollingAsyn({ value: JSON.parse(data) })
-                        }
-                        catch (e) {
-                            console.log(e);
-                        }
-                        data = "";
-                    }
-                    else {
-                        istrue = false;
-                    }
-                }
+
+                fun();
             }
             //结束重连
             else if (xhr.readyState == 4) {
@@ -84,8 +92,6 @@ U.MD.O.P.polling = function (params) {
     }
 }
 
-
-
 /* 
 * 处理从后台返回的数据
 *