开发者

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

开发者 https://www.devze.com 2023-04-06 04:25 出处:网络
I am setting up a login screen in jQuery Mobile. Upon submission. I want it to hit the auth.php, which wil开发者_Go百科l return a session key of some sort, and then load page #two in my index file.

I am setting up a login screen in jQuery Mobile.

Upon submission. I want it to hit the auth.php, which wil开发者_Go百科l 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"> 


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()


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').

0

精彩评论

暂无评论...
验证码 换一张
取 消