简体   繁体   中英

Redirect user to login page from JQuery autocomplete if not logged in

  1. When users log into my PHP website, they are automatically logged out after a period of inactivity.
  2. I have a few input fields on the main page for searching for stuff. Input type="text" with JQuery autocomplete option on them. The JQuery autocomplete takes user input and sends it to a PHP file that searches the database and returns data in JSON format.
  3. The original page displays the data returned in a clickable list.

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.

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.

How do I achieve the desired result?

在服务器端 ajax 首先检查登录条件,并根据它给出像 {login:false} 这样的响应,在你的 jquery 函数中检查该响应,如果 login=false 则使用 window.location 重定向。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM