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.