javascript - Only update messages when there is a connection -


I created a site display messages, so msgloader.js updates the message every 10 seconds with the administrator. The client continually displays this site on a screen.

The problem is that sometimes the internet connection is not very good, the display is disconnected and msgloader.js still updates the messages, finally freeze the screen (I know the reason is that There is also a clock on the site, the clock gets time from the local machine, it stabilizes only at a time until we refresh the page which is an issue).

I suspect that this freeze issue is because too many scripts are going on and machine RAM has been raised.

Back to the question, can we set down when there is an internet connection, every 10 seconds the update has the code in the message, otherwise every hour / message twice if there is no internet connection Updates

Any help is appreciated. Thank you.

  -------------------------------------- ---------------------------- Update the data for stable squares ------------- - ------------------------------------------------- --- * / function update signal (cult) {setTimeout ('update address (' + sect '' '', 10000); // Alert ('Update address:' + Cult); Var Ajax = new sack (); Ajax.requestFile = 'ajax / getmessages.php? Section = '+ cult; Ajax Method = 'post'; /*ajax.onError = error when; * / Ajax.on end = when expiration; Ajax.runAJAX (); / * Function when error () {Warning ('getMessages value can not be found & lt; br / & gt; Please notify system administrator.'); } * / When done full () {var message = ajax.response; Var Message 1 = Message. Split ('---'); Var num_messages = messages1 [0]; // warning ('number lines:' + num_messages); Var message_list = Message 1 [1]; // warning ('message:' message); Var msg_data_array = messages_list.split ('::'); Var i = 0; Switch (sect) {for case 1: (i = 0; i & lt; = num_messages; i ++) {var j = i + 1; Icon_to_use = 'icon' + j; // Set icon square var icon = document.getElementById ('icon_' + Sect + '_' + j); Icon_to_use.className = 'icon_pointer'; // Set Message Text ------------------------------------------- Var msgtext_array = msg_data_array [i] .split ('##'); // Here is the title ------------------------------------------ Var Messagetext_1a = Msgtext_array [1]; // here is the text ------------------------------------------ Var Messagetext_1 = Msgtext_array [2]; // Set the title position -------------------------------------- - var Msg_1a = document.getElementById ('msg_text_' + Cult + '_' + J + 'A'); // Set text space -------------------------------------- - var Msg_1 = document.getElementById ('msg_text_' + Sect + '_' + j); // Write in Title ------------------------------------------ - msg_1a InnerHTML = msgtext_1a; Msg_1.innerHTML = "& lt; img src = '[url_of_image]' /" gt; + Msgtext_1; // Write in Text ------------------------------------------ - msg_1. InnerHTML = (msgtext_1)? Divider + msgtext_1: msgtext_1; //msg_1a.style.borderBottom="2px solid white "; Msg_1a.style.borderBottom = "2px solid white"; Msg_1.style.borderBottom = "2px solid white"; } break; Default: Break; } // DEBUG If the debug report ('updateSection (): ID:' + msg_id + '
+ updateSection (): TIMEOUT:' + timeout + '

+ 'Rotate:' Rotate); } Else {debugReset (); }}} /

If I understand you right then you can do something like this:

Every time a terror incident has increased a counter over an AJAX request. After defining the limit of failure in one line / fails at a time, you change the length of time-out.

  var timeoutLength = 10000 setTimeout ('updateSection (' + sect ')', timeout length);   

After the AJAX request fails, changing the timeout langel is not an IE Internet connection.

Edit

  var ErrorGroup = 0; Ajax.onError = Error when; Function when error () {errorCount ++ (error log <5) {timeoutLength = 3600000}} during the integer () function {errorCount = 0 ...}   

5 errors are required in the line, assume that the Internet is down, you probably should play with it. But this will show you general ideas.

Comments