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
Post a Comment