I want to browser to show 403 (forbidden page) inside if() loop below in JavaScript (ie: replace window.location = 'unauth.html' statement.). I dont want to reroute to unauth.html page. How can I do that?
$(document).ajaxComplete(function (event, xhr, settings) {
if (xhr.responseText.indexOf('Unauthorized access') >= 0)
// Show unauthorized page
window.location = 'unauth.html';
});
You can use that callback function to replace the contents of your page. But I believe you cannot send a http 403 status code via ajax.
In order to clarify, you can get a HTTP status code via ajax but you will not be able to inject that status code to current page without redirecting it.