ming 3 years ago
parent
commit
728ce78d64
1 changed files with 20 additions and 10 deletions
  1. 20 10
      js/index.js

+ 20 - 10
js/index.js

@@ -1,3 +1,4 @@
+ let connectError = 0;
  // 站点工况(websocket实时推送)
  (function() {
 
@@ -30,11 +31,14 @@
                  websocket.send(JSON.stringify(json));
              };
              websocket.onclose = function(evt) {
-                 console.log("DisConnected.");
-                 $('.data-view').append('<div class="send-status">和服务器断开连接!</div>')
-                 scrollBottom();
-                 (function() {})()
-                 //  initWebSocket();
+                 if (connectError == 0) {
+                     console.log("DisConnected.");
+                     $('.data-view').append('<div class="send-status">和服务器断开连接!</div>')
+                     scrollBottom();
+                     (function() {})()
+                     //  initWebSocket();
+                 }
+
              };
              websocket.onmessage = function(evt) {
                  var siteData = eval('(' + evt.data + ')');
@@ -47,17 +51,23 @@
                      $('.data-view').append('<div class="receive-time">[' + siteData.time + ' 收到]</div>');
                      $('.data-view').append('<pre class="receive-request">' + JSON.stringify(siteData, null, 2) + '</pre>')
                      scrollBottom();
-
-
                  }
              };
 
              websocket.onerror = function(evt) {
-                 alert(1)
-                 console.log("Error:", evt.data);
-                 (function() {})()
+
+                 connectError = 1;
+                 //  isOpen = true;
+                 console.log("Error==:", evt.data);
+                 (function() {
+                     alert('连接失败,无效的地址');
+
+                 })()
+
              };
          } catch (exception) {
+             alert('无效的地址!')
+             connectError = 1;
              console.log("Exception:", exception);
              (function() {})()
          }