如何从jQuery GET搜索结果 [英] How do I search results from jquery GET
问题描述
我在调查脚本中get
的结果时遇到了一些问题.我得到以下代码来检查用户是否仍在登录:
I'm having a bit of a problem investigating the result from my get
in my script. I got the following code to check if a user is still logged in:
$.get("nowhereGet", function(result){
if($(result).find('[id="loginInput"]'))
{
//HTML is in the response then we have been logged out and the user needs to go to
window.location.href = "login";
}
});
现在,如果用户已登录,Struts将从我的获取中返回result
中的一个html页面.如果用户已注销,则将返回一个页面,其中包含id="loginInput"
元素.
我以为上面可以解决问题,但是没有爱.我在做什么错?
有没有比使用随机get
ping服务器更好的方法了?我需要一种使用ajax执行此检查的方法,并且注销时完成的任何get
或post
都会被拦截,结果将是登录页面而不是预期页面
Now if the user is logged in Struts will return one html-page in result
from my get. If the user has been logged out different page will be returned one with and element id="loginInput"
in it.
I thought the above would do the trick but no love. What am I doing wrong?
Is there a better way to do this than to ping the server with a random get
? I need a method that performes this check using ajax and any get
or post
done while logged out will get intercepted and the result will be the login-page instead of the intended page
推荐答案
我找到了其他解决方案,并在史蒂文·贝尼特斯(Steven Benitez)的帮助下,使它正常工作.点击链接以获取更多信息,但总之,我让拦截器代替了它.如果某个路径/动作被调用,拦截器将返回一个文本流,我可以从脚本中读取该文本流.
I found an other soloution and with help from Steven Benitez I got it working. Follow the link for more information but in short I let my interceptor do the work instead. If a certain path/action is called the interceptor will return a text stream that I can read from my script.
这篇关于如何从jQuery GET搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!