Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to periodically check until ajax return status values have changed?
    text
    copied!<p>How can i checkstatus of ajax response to wait and check that it has changed from 200 -->500 -->200? it has to be checked and recheck. Mine isnt working correctly here my code below. NoTe: On succesfull form submission it will always be 200 .. so it need to check and recheck for 500 and then for 200 before redirecting to the mainpage again.</p> <p>I tried to create checkstatus function so i can resuse. how can this be done correctly?</p> <pre><code> // setTimeout(function() { location.reload(true);}, 3000); function checkStatus() { /*** Re check bit ***/ var restartCheck = window.setInterval( $.ajax({ // dataType : 'jsonp', //jsonp : 'js', url: "../../../../../rest/configuration", beforeSend: function (jqXHR, settings) { console.info('in beforeSend'); console.log(jqXHR, settings); }, error: function (jqXHR, textStatus, errorThrown) { alert(" 500 top data still loading " + jqXHR + " : " + textStatus + " : " + errorThrown); console.info('in error'); console.log(jqXHR, textStatus, errorThrown); }, complete: function (jqXHR, textStatus) { alert(" complete " + jqXHR + " : " + textStatus); console.info('in complete'); console.log(jqXHR, textStatus); }, success: function (data, textStatus, jqXHR) { window.clearInterval(restartCheck); alert(" success " + jqXHR + " : " + textStatus); console.info('in success'); console.log(data, textStatus, jqXHR); } }), 3000); //This will call the ajax function every 3 seconds until the clearInterval function is called in the success callback. /*** recheck bit **/ } </code></pre> <p>/** On initial success form submission the success values is 200. After that I need to wait sometimes to check and recheck for 500 for server starts, when the Server restarts or is restarting it gives a 500 internal server message, it take about 30 to 40 sec or more to restart the server so i have await time for 30 sec.. Once the server restarts it gives a 200 success server message. and then redirect the page . SO i am trying to checkstatus until it changes from 200 --> 500 -200 **/</p> <pre><code> $.ajax({ type: "POST", url: "foo.json", data: json_data, contentType: 'application/json', success: function (data, textStatus, xhr) { console.log(arguments); console.log(xhr.status); alert("Your changes are being submitted: " + textStatus + " : " + xhr.status); $('#myModal').modal('hide'); $('#myModal-loading').modal('show'); //call function checkstatus not currently workign //statsu val ==200 server inital form success val from server setTimeout(function () { count=0; var statusval = checkStatus(); while(statusval == 200 and count &lt;=5) { statusval = checkStatus(); //statsu val has changed to 500 server is restarting if (statusval==500) { //wait for 30 sec to recheck if the server has restarted and changed to success ie 200 setTimeout(function () { checkStatus();}, 30000); } count++; }, 3000); alert("restartCheck " + restartCheck) setTimeout(function () { location.reload(true); }, 3000); // $('#myModal-loading').modal('hide'); $('&lt;div id="loading"&gt;Loading...&lt;/div&gt;').insertBefore('#myform'); //location.reload(true); }, error: function (jqXHR, textStatus, errorThrown) { // alert("Warning and error has occured: "+errorThrown + " : " + jqXHR.status); alert(jqXHR.responseText + " - " + errorThrown + " : " + jqXHR.status); } }); }); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload