在JavaScript中路由到403页
我想在浏览器中用JavaScript(即:replace window.location='unauth.html'语句)在下面的if()循环中显示403(禁止页面)。我不想重新路由到unauth.html页面。我该怎么做在JavaScript中路由到403页,javascript,browser,url-routing,http-status-code-403,Javascript,Browser,Url Routing,Http Status Code 403,我想在浏览器中用JavaScript(即:replace window.location='unauth.html'语句)在下面的if()循环中显示403(禁止页面)。我不想重新路由到unauth.html页面。我该怎么做 $(document).ajaxComplete(function (event, xhr, settings) { if (xhr.responseText.indexOf('Unauthorized access') >= 0)
$(document).ajaxComplete(function (event, xhr, settings) {
if (xhr.responseText.indexOf('Unauthorized access') >= 0)
// Show unauthorized page
window.location = 'unauth.html';
});
您可以使用该回调函数替换页面的内容。但是我相信您不能通过ajax发送HTTP403状态代码
为了澄清这一点,您可以通过ajax获得HTTP状态代码,但如果不重定向,您将无法将该状态代码注入当前页面。这不是循环,而是回调。它起作用了吗?有错误吗?什么样的错误?Tim,我不想使用unauth.html,而是想将该语句(window.location='unauth.html';)替换为显示403禁止页面的内容。我该怎么做?