jQuery Mobile -提交表单,重定向到页面id

jQuery Mobile - Submit a form, redirect to a page id?

本文关键字:id 重定向 Mobile 提交 表单 jQuery      更新时间:2023-09-26

我在jQuery Mobile中设置一个登录屏幕。

提交。我希望它击中auth.php,它将返回某种类型的会话键,然后在我的索引文件中加载页面# 2。

所以我的主要问题是:我如何点击auth.php并在我的索引中加载页面# 2。

<!--index.php-->
<form action="auth.php" method="post">
  <div class="ui-body ui-body-b">
    <input type="text" name="name" id="name" value="" class="ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" placeholder="Username">
    <input type="password" name="name" id="name" value="" class="ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" placeholder="Password"> 
    <fieldset class="ui-grid-a"> 
      <div class="ui-block-a"><button type="reset" data-theme="d">Reset</button></div> 
      <div class="ui-block-b"><button type="submit" data-theme="a">Login</button></div> 
    </fieldset> 
  </div>
</form>

然后我需要它在我的索引文件加载页面# 2。我的索引中有多个页面,这是处理这个问题的最好方法吗?

<!-- Start of second page: #two in index.php--> 
<div data-role="page" id="two" data-theme="a"> 

您应该重新设计,使auth.php重定向到返回正确站点的视图。JQM自己会处理得很好。

尽管我不喜欢这个主意,但我可以帮你按你的方式做。

你需要自己用$.post()发布表单,在auth.php返回确认后,存储令牌或将其留给基于cookie的默认会话机制,然后用$.mobile.changePage()重定向

jQuery mobile被设计成总是让用户在同一个页面上,所以这是违背设计的。你有几个选择来做正确的方式:选项1。在一个不可见的iframe中加载auth.php,加载完成后,将页面重定向到complete.php。在索引页中,您可能希望显示一个微调器并设置一个计时器来检查iframe的来源,当它发生变化时,切换到# 2。第二个选项。与选项1类似,您将使用表单信息向auth.php发出ajax请求,并等待它完成。当请求完成返回时,您可以切换到# 2。

如果您真的想重定向到auth.php并返回到索引# 2,那么您需要在重定向期间添加一个参数。例如,auth.php将重定向到index.php?start= 2,然后在你的PHP或Javascript中,你可以使# 2默认的起始页(例如。检查$_GET['start'] == 'two')