javascript - jQuery Mobile showPageLoadingMsg()/hidePageLoadingMsg() 方法仅适用于 Firefox 浏览器

标签 javascript jquery jquery-mobile

我尝试在用户点击后使用 jquery mobile $.mobile.showPageLoadingMsg() 登录按钮。执行此操作后,我将对 Web 服务进行 ajax 调用 得到回复后我隐藏了加载消息。问题 问题是加载程序仅在 Firefox 浏览器中显示,而在其他浏览器(chrome、safari、android)中不显示。

示例:

$.mobile.showPageLoadingMsg();
var response = $.ajax(
 {
   type: "POST",
   url: "service.php",
   data: "...",
   async: false,
   dataType: "json",
   cache: false
   });
   response.success(function (data)
    {
    res_content = data;
    });
    response.error(function (jqXHR, textStatus, errorThrown)
    {
  }
 $.mobile.hidePageLoadingMsg();

我还发现,如果我给 隐藏PageLoadingMsg。

setTimeout(function(){$.mobile.hidePageLoadingMsg()},5000);

加载程序需要更多时间才能显示,即它在 ajax 调用后显示并显示 5 秒。因为给出超时并不是解决办法。 请帮忙。

最佳答案

首先,$.mobile.showPageLoadingMsg()$.mobile.hidePageLoadingMsg()deprecated从 jQM 版本 1.2 开始。 请改用 $.mobile.loading('show')$.mobile.loading('hide')

话虽这么说,你可以尝试类似的事情

$("#btn1").click(function(){
    $.mobile.loading('show', {theme:"e", text:"Please wait...", textonly:true, textVisible: true});

    //Do your ajax call and processing here
    setTimeout(function(){
        $.ajax({
            ...
            success: function (data){
                ...
                $.mobile.loading('hide');
            }
        });
    }, 50);
});

参见jsFiddle在这里模拟漫长的工作

关于javascript - jQuery Mobile showPageLoadingMsg()/hidePageLoadingMsg() 方法仅适用于 Firefox 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14556289/

相关文章:

javascript - Google Drive API - 复制现有的电子表格文件并使用 JavaScript Client API 设置 "title"

Javascript 数字与负值的比较不起作用

javascript - JqueryMobile 布局是否可以在 Web 和移动设备上运行

javascript - 用于 jquery mobile 的带空白的 ListView

javascript - 从 index.html 打开 quiz.html 页面时怀疑 javascript 未加载

javascript - 执行 3 个返回 true/false 的函数,如果所有函数都返回 true,则执行某些操作,否则不短路

javascript - 在jsnetworkx中绘制平行边

javascript - clearTimeout 当一个函数被多次调用时

javascript - Jquery Tablesorter 自定义日期

jQuery .serialize() 表单数据