ajax - Is it possible to get a browser window to update while it is in a Javascript loop? -


I have an Ajax call which is currently synchronous though, as long as this Ajax call is being executed, the browser The interface is freezing until the call is returned. In the case of timeouts, it can freeze the browser for anyone.

Is there a way to refresh the browser (a browser) user interface, but no javascript is executed? Ideally this will be some command like window.update () , which will refresh the user interface thread.

If this is possible, then I can replace synchronous AJAX calls with something like:

  obj = do_async_ajax_call (); While (! Obj.hasReturned ()) {window.update (); } // synchronous call  

can start again setTimeout , or resume the function in the callback, this That the performance flow can not be interrupted: (There are many state variables that all depend on each other, and long_function () is to start the flow again in any way): < / P>

  function Long_function () {// Many codes, variables' a ',' b ', ... writes, if (sync_call_is_true ()) {// Many codes,' a ',' B ', Writes / writes ...} else {// Many codes, variables' a ',' b ', ...} // reads many codes, writes' variable' a ',' b ',. .. reads calculation_value; }  

Change your synchronous request with an asynchronous request and use the callback is required. An exaggerated example would be:

  obj = do_async_ajax_call (function (data, success) {if (success) {// continue ...}}); Function do_async_ajax_call (callback) {var xhr = new XMLHttpRequest (); Xhr.open ("GET", "http://mysite.com", true); Xhr.onreadystatechange = function () {if (xhr.readyState == 4 & amp; amp; xhr.status == 200) Callback (xhr.responseXML, true); Else if (xhr.readyState == 4) Callback (empty, inaccurate); } Xhr.send (); }  

In this way you are passing an anonymous function as a parameter for the AJAX request function. When Ajax is completed, that function was passed, it was passed the reply XML. In the meantime, the browser has been free to talk about it normally until the call is completed. From here, your remaining code is in progress.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -