[英]Redirect user to login page from JQuery autocomplete if not logged in
Now, if users have been logged out due to inactivity, this isn't immediately obvious, unless of course they choose to reload the page.现在,如果用户由于不活动而被注销,这并不是很明显,除非他们当然选择重新加载页面。 Most don't, however.
然而,大多数人没有。 So if they just start entering search words, they just get nothting, because they're not logged in.
所以如果他们刚开始输入搜索词,他们什么也得不到,因为他们没有登录。
I already have a routine to redirect users to the login page if they're not logged in. But this doesn't work in this case, because it's the JSON-generating page that is being redirected, that that doesn't really have any influence on the main page.如果用户未登录,我已经有一个例程将用户重定向到登录页面。但这在这种情况下不起作用,因为它是正在重定向的 JSON 生成页面,实际上没有任何对主页的影响。
Also, I can't see how I can interact directly with what's being returned - it seems like JQuery does all of the data handling internally, so I can't really grab onto data returned and tell the main page to redirect in that case.此外,我看不到如何直接与返回的内容进行交互 - 似乎 JQuery 在内部完成所有数据处理,因此在这种情况下我无法真正获取返回的数据并告诉主页进行重定向。
How do I achieve the desired result?我如何达到预期的结果?
在服务器端 ajax 首先检查登录条件,并根据它给出像 {login:false} 这样的响应,在你的 jquery 函数中检查该响应,如果 login=false 则使用 window.location 重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.