jQuery Mobile$.Mobile.changePage()在天堂遇到麻烦(不是更改页面)

jQuery Mobile$.Mobile.changePage()在天堂遇到麻烦(不是更改页面),jquery,jquery-mobile,event-handling,Jquery,Jquery Mobile,Event Handling,我有一个简单的登录表单。2个php文件,mobile.login.php和mobile.home.php。您登录,如果设置了cookie,现在就可以访问主页。登录系统工作,但页面不会更改为mobile.home.php,它只是再次显示登录表单。表单是Ajax,下面是代码: <script type="text/javascript"> $('#login').live('pageinit', function() { $('form').live('submit', func

我有一个简单的登录表单。2个php文件,
mobile.login.php
mobile.home.php
。您登录,如果设置了cookie,现在就可以访问主页。登录系统工作,但页面不会更改为
mobile.home.php
,它只是再次显示登录表单。表单是Ajax,下面是代码:

<script type="text/javascript">
$('#login').live('pageinit', function() {
    $('form').live('submit', function(e){
        e.stopPropagation();
        e.preventDefault();

        $.post($(this).attr('action'), $(this).serialize(), function(data){
            if(data.success) {
                //$.mobile.changePage($('#home'), { transition: 'slideup'});
                $.mobile.changePage('mobile.home.php', 'slide', false, true);
                e.preventDefault();
            } else {
            alert('Login failed.');
            return false;
            }
       }, 'json');
    });
});
</script>

$('#login').live('pageinit',function(){
$('form').live('submit',函数(e){
e、 停止传播();
e、 预防默认值();
$.post($(this.attr('action'),$(this.serialize()),函数(数据){
if(data.success){
//$.mobile.changePage($('#home'),{transition:'slideup'});
$.mobile.changePage('mobile.home.php','slide',false,true);
e、 预防默认值();
}否则{
警报('登录失败');
返回false;
}
}“json”);
});
});
我试过很多东西。正如你所看到的,我有两个选项来更改代码中的页面,一个被注释掉了。被注释掉的那个,什么也没发生。激活的代码将url更改为
mobile.home.php
,但只是
再次向上滑动登录表单。
mobile.login.php
mobile.home.php
都有页面divs
id


我似乎不明白,有什么想法吗?

这应该是你的问题:

$.mobile.changePage('mobile.home.php', 'slide', false, true);
e.preventDefault();
不要使用e.preventDefault()在这里,它将阻止成功的转换

下面是一个简单的例子:


注释/取消注释e.preventDefault()查看差异。

在深入研究代码时,它可能必须执行COOKIE,我将向您报告。这是正确的。另外,我忘了,因为主页并不是专门加载cookies来阅读的。我不得不使用jQuery$.post来阅读cookies。