ExtJs定時消息提示框,相似於QQ右下角提示,ExtJs如何定時向後臺發出兩個請求並刷新數據實例

原文出自:https://blog.csdn.net/seesun2012
html

思路:
1.加載頁面,加載Ext.TaskManager.start()方法;
2.執行定時器方法;
3.獲取地址向後臺發送請求,參數傳遞到後臺;
4.執行你想要的功能。windows

/**
 *  定時器結構
 */
var task = {
    run : function() {
        //請求...
    },
    interval : 1000,  //1秒
};
Ext.TaskManager.start(task);

一言不合就Copy:ide

/**
 *
 * 時間:2016-10-17
 * 
 * 做者:張擎宇
 */
Ext.define('Ext.xxx.xxx.xxx.xxx', {
    extend : 'Ext.xxx.xxx.xxx.xxx',
    //初始化
    init : function() {
        var self = this;
        self.control({
            //頁面加載時這行render中的方法
            render : function(panel) {
                var num = 1;        
                var dataOne = 0;    
                var dataTwo = 0;    

                var task = {
                    run : function() {
                        if (num >= 1 && num <= 100 ) {
                            
                            //請求一
                            Ext.Ajax.request({
                                url : 'xxxxxx/xxxxxx',  //後臺請求地址
                                params : {
                                    name : 'xxx',   //傳遞的請求參數
                                },
                                success : function(record)
                                {
                                    dataOne = Ext.JSON.decode(record.responseText); //獲取的請求結果
                                }
                            });
                            
                            //請求二
                            Ext.Ajax.request({
                                url : 'xxxxxx/xxxxxx',
                                params : {
                                    id : 0001,
                                    name : 'seesun2012',
                                    age : '120',
                                },
                                success : function(record)
                                {
                                    dataTwo = Ext.JSON.decode(record.responseText);
                                    var reusable = Ext.getCmp('windows_Id');
                                    if (!reusable && (dataOne > 0 || dataTwo > 0)) {
                                        //建立一個窗體
                                        reusable = Ext.create('Ext.window.Window', {
                                            title : '窗體',
                                            heiht : 400,
                                            width : 300,
                                            id : 'windows_Id',      
                                            closeAction : 'hide',
                                            position : 'br',
                                            useXAxis : false,
                                            html : '<div style="width:300px;height:150px;margin-top:10px;">請求成功,xxxxx!</div><hr /><hr/><span style="with:100%;float:right;margin-right:10px;"><a id="dont_msg" href="#" style="color:blue;text-decoration:none;a:hover:red;">再也不提醒</a></span>',
                                        });
                                        reusable.show();
                                    }
                                    //再也不彈出提示
                                    $('#dont_msg').on('click',function(){
                                        num = 100;
                                        reusable.destroy();     //銷燬這個窗體
                                    });
                                    num++;  //若是成功,累加當前請求次數
                                }
                            });
                        }
                    },
                    interval : 10000,   //定時10秒鐘向後臺發一次請求
                    
                };
                Ext.TaskManager.start(task);

            }

        });
    },
});

固然要根據實際狀況更改一些相應的代碼啦~~~!this

相關文章
相關標籤/搜索