zoukankan      html  css  js  c++  java
  • jQuery Mobile 手动显示ajax加载器

    在jquery mobile开发中,经常需要调用ajax方法,异步获取数据,如果异步获取数据方法由于网速等等的原因,会有一个反应时间,如果能在点击按钮后数据处理期间,给一个正在加载的提示,客户体验会更好一些。

    先看两个方法,显示和关闭,方法来自于参考:http://blog.csdn.net/zht666/article/details/8563025

    复制代码
    <script>  
    //显示加载器  
    function showLoader() {  
        //显示加载器.for jQuery Mobile 1.2.0  
        $.mobile.loading('show', {  
            text: '加载中...', //加载器中显示的文字  
            textVisible: true, //是否显示文字  
            theme: 'a',        //加载器主题样式a-e  
            textonly: false,   //是否只显示文字  
            html: ""           //要显示的html内容,如图片等  
        });  
    }  
      
    //隐藏加载器.for jQuery Mobile 1.2.0  
    function hideLoader()  
    {  
        //隐藏加载器  
        $.mobile.loading('hide');  
    }  
    </script>  
    复制代码

    然后在ajax中调用:

    复制代码
    //获取进度
    function InsertStatus(matterID, obj) {
        var a = $(obj).parent().parent().parent();
        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "/ToDoList/InsertStatus/?matterID=" + matterID,
            beforeSend: function () {         
                showLoader();
            },
            complete:function(){       
                hideLoader();
            },
            success: function (msg) {
                if (msg > 0) {
                    $("#popdiv").text("获取进度成功");
                } else {
                    $("#popdiv").text("获取进度失败");
                }
                //弹出提示信息
                $("#GettingProgress").attr('data-rel', 'dialog');
                $("#GettingProgress").trigger('create');
                $("#popdiv").popup("open");
                setTimeout(function () { $("#popdiv").popup("close"); }, 2000);
            }
        });
    
    }
    复制代码

    这样就可以在数据处理过程中,有加载中的效果。

    参考:http://www.cnblogs.com/hiflora/p/3816212.html

    http://blog.csdn.net/zht666/article/details/8563025

  • 相关阅读:
    Hive安装教程
    HBase安装教程
    Hadoop集群搭建
    Redis集群安装详细步骤
    Python绘图工具turtle库的使用
    python程序语法元素分析
    Selenium请求库爬取京东商品实例
    python爬虫入门
    python入门
    pytest fixture场景一:参数传入
  • 原文地址:https://www.cnblogs.com/youxin/p/4192530.html
Copyright © 2011-2022 走看看