0

I am new to UI development. I am making an ajax call and on success I am redirecting the page to a different URL. In the meantime till the browser redirects, the initial page is getting loaded. How to avoid the page to load and redirect the page? I tried with setting the timeout but did not help, I am providing the source code below which I am trying to use:

Inside the javascript file which is loaded in the index.html file:

$.ajax({
   type: 'GET',
    url: "https://REST call for authentication",
    async: false,
    contentType: "application/json",
    dataType: 'jsonp',
    success: function(data) {
       if(!data.isAuthenticated){
           window.location = _authUrl; //redirect to a different URL
       }
    },
    error: function() {
       console.log('Unable to validate. Possibly auth side is down.');
    }
});

//Intended behaviour: In case of a redirect don't load the current page.

Please let me know how to implement this.

Pradeep
  • 753
  • 7
  • 15
  • 25
  • see this question http://stackoverflow.com/questions/8943219/how-to-stop-page-load-in-html-static-page – giannisf Sep 22 '14 at 08:07
  • Check the authentication from the server side and do the redirection if necessary. It can be more efficient + secure than a client side redirection. – Susantha Sep 22 '14 at 08:23
  • Maybe, you should think of a very basic redirect page. The question, Giannis referred to looks like a dirty hack. – Benedikt Sep 22 '14 at 08:28

0 Answers0