doumeba0486 2011-09-09 22:46
浏览 53
已采纳

jQuery Mobile表单ajax帖子不工作?

I'm currently creating a simple jQuery Mobile sign in page. 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. It is just the same page that I entered the login information on.

Am I using jQuery Mobile's form system wrong?

  • 写回答

1条回答 默认 最新

  • dongping4273 2011-09-15 21:28
    关注

    You may want to consider turning off Ajax, while you are troubleshooting your form submission. The Ajax handling of form submissions inside JQuery Mobile is implemented automatically to create a smooth transition between the form and the result. Details, here. To submit a form without Ajax, you can either disable Ajax form handling globally, or per form via the

    data-ajax="false"
    

    attribute. Or, globally,

    $(document).bind("mobileinit", function () {
       $.mobile.ajaxEnabled = false;
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable