处理 Ajax 响应的 302 响应代码

发布于 2025-01-04 13:35:53 字数 296 浏览 7 评论 0原文

我在网络应用程序中使用 YUI 2.9.0。在 Ajax 调用的情况下,当用户会话过期时,服务器会向登录服务器发送一个带有位置参数设置的 302-Moved Temporarily 响应。

Web应用程序域和登录服务器域不同。我在重定向中遇到问题,因为 Firefox 不会自动重定向到登录服务器(我认为这是因为不同的域)。

我已经验证了重定向发生,并且当重定向到同一域中的不同页面时,我的 ajax 回调函数正在获取新位置的内容作为响应。

有什么办法可以解决这个问题吗?我确信,如果是由于跨域重定向,这将是一个非常常见的问题。

I'm using YUI 2.9.0 in a web application. In case of Ajax calls, when user session got expired, the server sends a 302-Moved Temporarily response with the location parameter set to the login server.

The web app domain and the login server domain are different. I face problem in redirection as firefox does not redirect automatically to the login server (i assume it is because of different domains).

I have verified that redirection happens and my ajax callback functions are getting the new location's content as response, when the redirection is to a different page in the same domain.

Is there any way to work around this problem. I'm sure this will be a very common problem if it is because of cross domain redirect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁微风不噪 2025-01-11 13:35:53

您可以使用下面的代码作为解决方法
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//正常流程
}
//如果找到302则将运行其他部分
别的{
//重定向代码
}

you can use below code as workaround
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//normal flow
}
//if 302 found then will run else part
else{
//code to redirect
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文