简体   繁体   English

jQuery Mobile表单ajax发布不起作用?

[英]jQuery Mobile form ajax post not working?

I'm currently creating a simple jQuery Mobile sign in page. 我目前正在创建一个简单的jQuery Mobile登录页面。 Here's my code: 这是我的代码:

<div data-role="page"> 
    <div data-role="header"><h1>Header</h1></div>
    <?php

    if(isset($_POST['username']) && isset($_POST['password'])){
        die("hello");
    } 

    ?>
    <div data-role="content">
        <form method="post">
                <div data-role="fieldcontain">
                <label for="username">Username:</label>
                <input id="username" type="text" name="username" />
            </div>
            <div data-role="fieldcontain">
                <label for="password">Password:</label>
                <input id="password" type="password" name="password" />
            </div>
            <input type="submit" value="Sign In" data-inline="true" data-theme="b" />
        </form>
    </div>
    <div data-role="footer"><h4>Footer</h4></div>
</div>

Whenever I type in a username and password, using firebug, I can tell that the correct post was sent, however, the page that is returned through ajax to load into the page does not have the die("hello") in it. 每当我使用Firebug输入用户名和密码时,我都可以知道发送了正确的帖子,但是,通过ajax返回并加载到该页面的页面中没有die("hello") It is just the same page that I entered the login information on. 这与我在其中输入登录信息的页面相同。

Am I using jQuery Mobile's form system wrong? 我使用jQuery Mobile的表单系统错了吗?

You may want to consider turning off Ajax, while you are troubleshooting your form submission. 在对表单提交进行故障排除时,您可能需要考虑关闭Ajax。 The Ajax handling of form submissions inside JQuery Mobile is implemented automatically to create a smooth transition between the form and the result. 自动实现JQuery Mobile中的表单提交的Ajax处理,以在表单和结果之间创建平滑过渡。 Details, here . 详细信息, 在这里 To submit a form without Ajax, you can either disable Ajax form handling globally, or per form via the 要提交不包含Ajax的表单,您可以全局禁用Ajax表单处理,也可以通过

data-ajax="false"

attribute. 属性。 Or, globally, 或者在全球范围内

$(document).bind("mobileinit", function () {
   $.mobile.ajaxEnabled = false;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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