Browser keeps "connecting" after jQuery Ajax request times out -


i have list of ip addresses couple of servers need pinged see if running. ip addresses stored in data-ip-address attributes of list of span elements, javascript function reads them in order, pings each of them, , displays result. more simplified version of full function this:

function pingservers() {   if($('span[data-ping-this]').length > 0) {     element = $('span[data-ping-this]:first');     $(element).removeattr('data-ping-this');     var url = $(element).attr('data-ip-address');      $.ajax({       url: url,        datatype: 'jsonp',       timeout: 4000,       success: function(response) {           displaysuccess();       },       error: function(something){           displaywarning();       }     });      settimeout(function(){       pingservers();     }, 1000);   } } 

the main thing there timeout defined, , timeout working, because after 4 seconds of no response, warning displayed. browsers, both firefox , chrome, still showing status message connecting (in bottom-left corner). firefox shows connecting <ip address> message, while chrome shows connecting..., , favicon in tab keeps being animated loading icon.

if keep tab open, goes on forever. if change tabs enough times, status message (and loading icon) goes away (never without changing tabs). interesting thing that, after goes away, if initiate function again via javascript (not reloading page), connecting message doesn't show @ anymore. though should in case. how this, returning data-ping-this attribute 1 of span elements, , run function again.

$('span:first').attr('data-ping-this', 'true'); pingservers(); 

so, can fixed on jquery side, , if so, how? or bug in browsers?

shortly: bug of jsonp.

explanation: jsonp not real xmlhttprequest, it not ajax call. jsonp hacky attempt perform cross-domain requests requesting remote script different domain, see wikipedia learn more.

what jquery inside, performs javascript call adding

<script src='your_pinging_address'></script> 

this way make jsonp request. comes timeout, settimeout, found out on jquery side timeout reached , call callback function; meanwhile browser has no idea timeout because artificial, goes on waiting remote script.

in other words: every ajax request jsonp has timeout on browser side. jsonp timeout piece of jquery art.

i cannot point line of code serve timeout in current jquery. had similar problem couple of years ago old jquery version, logically should stay was.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -