javascript - Equivalent to XMLHttpRequest timeout in synchronous JS -


having little bit of trouble understanding why timeout wouldn't work in synchronous js. script synchronous , need able timeout exception deals it, possible?

i've attempted research implementations (using settimeout etc.) seem instantly run following code , skip trying connect, if timeout set 0ms.

        function httpget(theurl) {             try {                 var xmlhttp = new xmlhttprequest();                 xmlhttp.open("get", theurl, false);                 xmlhttp.timeout = 3000;                 xmlhttp.send(null);                 notifyuser("success", "<b>success</b> have synced server.");                 return xmlhttp.responsetext;             } catch (e) {                     console.log("connection failed, grabbing local");                     notifyuser("info", "<b>connection failed</b> using local database - edits not saved!(yet)");                     return offlinepopulate();             }  } 

ended making asynchronous jquery.get

$.get( theurl, function( data ) {                //panic             }).done(function(data) {                console.log("success");              }).fail(function() {                 console.log("fail");              }); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -