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

£可爱£侵袭症+ 提交于 2021-02-16 20:08:34

问题


I am setting up a login screen in jQuery Mobile.

Upon submission. I want it to hit the auth.php, which will return a session key of some sort, and then load page #two in my index file.

So my main question is: How do I hit auth.php and also load page #two in my index.

<!--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>

Then I need it to Load page #two in my Index file. I have mulitple pages in my index..is this the best way to handle this?

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

回答1:


You should redesign so that the auth.php redirects to a view that returns a correct site. JQM will handle it itself wery well.

Having said that I can help you do it your way despite I don't like the idea :)

You need to post the form yourself with $.post() and after auth.php returns confirmation - store the token or just leave it to default session mechanizm based on cookies and then redirect with $.mobile.changePage()




回答2:


jQuery mobile is designed to always keep user on the same page, so this is going against the design. You have a few options to do it the right way: Option 1. Load auth.php in an invisible iframe, when it's done, redirect the page to complete.php. In your index page you would want to display a spinner and setup a timer that checks the source of the iframe and when it changes, switch over to #two. Option 2. Similar to option 1, you would do an ajax request to auth.php with the form information, and wait for it to complete. When request comes back complete, you can switch to #two.

If you really want to redirect to auth.php and back to index with #two, then you would need a parameter that gets added during redirect. For example, auth.php would redirect to index.php?start=two and then in your PHP or Javascript you can make #two the default starting page (eg. check for $_GET['start'] == 'two').



来源:https://stackoverflow.com/questions/7478240/jquery-mobile-submit-a-form-redirect-to-a-page-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!