处理 Ajax 响应的 302 响应代码
我在网络应用程序中使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用下面的代码作为解决方法
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
}