服务器会话超时时的 JSON/AJAX 问题
我正在网站内进行 ajax 和 json 调用,服务器端的会话超时为 120 分钟。时间到期后,用户尝试从已加载的页面进行 ajax 或 json 调用,调用后我只是坐在那里没有任何响应。我正在使用 Sturts.xml 文件来处理所有操作/URL 调用,并且该文件有一个拦截器,该拦截器会在每次对服务器进行的调用时运行。拦截器检查您是否已登录,如果未登录,则将您发送到登录屏幕。问题是 ajax 和 json 调用将全部设置如下:
*我必须替换所有“<”和“>”带有“(”和“)”的标签,因为编辑器不会显示它们,所以只需将括号替换为“>”和“<”
(操作名称=“someAction”类=“ActionClass”方法=“someMethod”) (结果名称=“成功”类型=“json”) (参数名称=“目标”)结果(/参数) (参数名称=“模式”) -*.class(/param) (/结果) (/action)
当拦截器想要将您发送到如下指定的登录页面时,将调用一个全局结果:
(result name="login" type="tiles")site.login(/result
)拦截器发送回“登录”结果而不是“成功”,ajax和json调用永远不会收到它期望的结果,当我查看响应时,浏览器收到的结果是我期望的页面的原始html重定向到。如果您的会话超时,任何其他类型的服务器调用都会起作用并将您发送到登录屏幕。如果我尝试像常规 lin 一样进行操作调用,它会工作,但我无法进行任何 ajax 或 json 调用并使其工作。有什么建议吗?
I am making ajax and json calls within my site that has a session timeout of 120 minutes on the server side. After the time has expired and a user tries to make an ajax or json call from a page that has been loaded, the call gets made I just sit there with no responds. I am using a sturts.xml file to handle all my action/url calls and this file has an interceptor that runs with every call that gets made to the server. The interceptor checks if you are logged in and sends you to the login screen if you are not. The problem is that the ajax and json calls will are all set up like below:
*I had to replace all "<" and ">" tags with "(" and ")" since the editor wont show them, so just replace the brackets with ">" and "<"
(action name="someAction" class="ActionClass" method="someMethod")
(result name="success" type="json")
(param name="target")result(/param)
(param name="patterns") -*.class(/param)
(/result)
(/action)
There is a global result that will be called when the interceptor wants to send you to the login page as specified below:
(result name="login" type="tiles")site.login(/result)
since the interceptor sends back a result of "login" and not "success", the ajax and json calls never receives the result it is expecting and when I look at the responds the browser receives it is the raw html of the page I am expecting to be redirected to. Any other type of server call works and sends you to the login screen if your session has timed out. If i try to make an action call as a regular lin, it will work, but I can't make any ajax or json calls and get it to work. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能有点 hackish,但这是我在 php 中所做的(不确定您使用的是什么语言):
ajax 调用返回脚本标记,该标记会将当前页面重定向到您的登录页面。再次不确定您是否正在使用它,但您可以使用 php 检测 ajax 请求。这可能不是最好的方法,但我已经使用它一年左右了,而且每次都很完美。希望这至少能给你一些想法。
读者,如果您认为这个解决方案是一个坏主意,请发表评论并告诉我原因,我想知道,因为我在所有项目中都使用它。
This is probably a bit hackish, but here's what I do in php (not sure what language you're working with):
The ajax call returns the script tag which will redirect the current page to your login page. Once again not sure if you're using it, but you can detect ajax requests with php. This is probably not the best way to do it, but I've been using it for a year or so and it works perfectly every time. Hopefully this will give you some ideas at least.
Readers, please comment if you think this solution is a bad idea and tell me why, I'd like to know because I am using it in all my projects.