jQuery Mobile - AJAX JSON

发布于 2024-12-12 03:00:21 字数 961 浏览 4 评论 0原文

我无法弄清楚为什么 jQuery Mobile 不会在 AJAX 调用中处理我的 json 返回。它在任何网络浏览器中都可以正常工作,但在我的手机(android)上却不行。脚本只是挂起,它甚至不会选择 success 函数中的任何一个 if 语句选项。

$('#loginSubmit').click(function() {
    $.mobile.showPageLoadingMsg(); 
     $.ajax({
                  type: "POST",
                  url: "/include/login.php",
                  data: $('#loginForm').serialize(),
                  cache: false,
                  dataType: "json",
                  success: function (json) {
                        if(json && json.error != '') {
                            //alert(json.error);
                            $.mobile.hidePageLoadingMsg();                              
                        } else {
                            $.mobile.changePage('/mobile/cp/', { transition: "slide" });
                            $.mobile.hidePageLoadingMsg();
                        }
                  }
                });

    return false;
});

I am having trouble figuring out why jQuery Mobile will not handle my json return in an AJAX call. It works perfectly fine in any web browser but not on my mobile phone (android). The script just hangs, it will not even choose either of the if statement options in the success function.

$('#loginSubmit').click(function() {
    $.mobile.showPageLoadingMsg(); 
     $.ajax({
                  type: "POST",
                  url: "/include/login.php",
                  data: $('#loginForm').serialize(),
                  cache: false,
                  dataType: "json",
                  success: function (json) {
                        if(json && json.error != '') {
                            //alert(json.error);
                            $.mobile.hidePageLoadingMsg();                              
                        } else {
                            $.mobile.changePage('/mobile/cp/', { transition: "slide" });
                            $.mobile.hidePageLoadingMsg();
                        }
                  }
                });

    return false;
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我爱人 2024-12-19 03:00:21

当我启用 ajaxLinks 时,我在新的测试版中曾经遇到过这个问题。如果我想为不在我的起始页上的元素添加代码,我无法使用

$(document).ready 函数

我使用

$('#page').live('pageshow', function() ...

在 pagechange 中添加代码。所以我想添加 javascript 的元素当前已呈现。

希望这有帮助。

I had this problem once with the new beta, when i enabled ajaxLinks. If i then wanted to add code for elements, that were not on my startpage, i could not use

$(document).ready function.

I used the

$('#page').live('pageshow', function() ...

to add my code at pagechange. So my elements i wanted to add the javascript to were currently rendered.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文