简体   繁体   English

如果未登录,则将用户从 JQuery 自动完成重定向到登录页面

[英]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.当用户登录我的 PHP 网站时,他们会在一段时间不活动后自动注销。
  2. I have a few input fields on the main page for searching for stuff.我在主页上有一些输入字段用于搜索内容。 Input type="text" with JQuery autocomplete option on them. Input type="text" 带有 JQuery 自动完成选项。 The JQuery autocomplete takes user input and sends it to a PHP file that searches the database and returns data in JSON format. JQuery 自动完成接受用户输入并将其发送到一个 PHP 文件,该文件搜索数据库并以 JSON 格式返回数据。
  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.如果用户未登录,我已经有一个例程将用户重定向到登录页面。但这在这种情况下不起作用,因为它是正在重定向的 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.

相关问题 使用php将登录用户从登录页面重定向到用户仪表板 - Redirect a logged in user from login page to user dashboard with php 如果用户尚未登录Angular JS,则重定向到登录页面 - Redirect to a login page if the user is not yet logged in Angular JS 如果未使用AngularFire 2登录,则重定向到登录页面 - Redirect to login page, if not logged in with AngularFire 2 React MongoDB 电子商务网站。 如果用户已经登录,如何从“帐户”按钮重定向到用户信息而不是登录页面? - React MongoDB E-Commerce website. If user is already logged in, how to redirect from "Account" button to User info instead of Login page? Bigcommerce-如果未登录,如何将用户从首页重定向到登录页面 - Bigcommerce - How to redirect users to login page from homepage if not logged in 将用户重定向到登录页面 - redirect user to login page 如何防止用户登录后看到登录页面? - How to prevent user from seeing login page after logged in? 如果用户未登录,则Node.js重定向到登录 - Node.js redirect to login if user is not logged in 登录页面重定向 - 如果未登录,则使 HTML 无法访问 - Login Page Redirect - Make HTML inaccessible if not logged in 如果用户尚未登录Java servlet,如何重定向到jsp登录页面? - How to redirect to jsp login page, if user does not logged in already, Java servlet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM