Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript interrupt Page request

I have a page that sends a request to the server. On the server we then send a synchronous request to a third party web API. Because of the call to the web API we never have complete control over how long our server side processing will take. So, what I would like to do is write a javascript function that will interrupt this page request and forward the user to an error page after so much time. So my javascript would look a little like this.

function onSubmit() {
   var oneMinute = (60 * 1000);
   setTimeout(function(){ window.location.replace("http://errorPage.html"); }, oneMinute);
   return true;
}

The problem is that even when the timeout method is executed the page still waits for a response from the server before redirecting to the error page. Is there a way to interrupt the page request so that it doesn't wait until a response is received before redirecting to the error page?

like image 828
Mark Rucker Avatar asked Jan 23 '26 10:01

Mark Rucker


1 Answers

You can try this , not sure whether it will work in all the browsers.

function onSubmit() {
   var oneMinute = (60 * 1000);
   setTimeout(function(){ 
        if($.browser.msie){
            document.execCommand('Stop');
        }
        else{//Other browsers
            window.stop(); 
        }
        window.location.replace("http://errorPage.html"); 
   }, oneMinute);
   return true;
}
like image 71
ShankarSangoli Avatar answered Jan 25 '26 06:01

ShankarSangoli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!