ExtJs定时消息提示框,类似于QQ右下角提示,ExtJs如何定时向后台发出两个请求并刷新数据实例

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

思路:
1.加载页面,加载Ext.TaskManager.start()方法;
2.执行定时器方法;
3.获取地址向后台发送请求,参数传递到后台;
4.执行你想要的功能。

/**
 *  定时器结构
 */
var task = {
    run : function() {
        //请求...
    },
    interval : 1000,  //1秒
};
Ext.TaskManager.start(task);

一言不合就Copy:

/**
 *
 * 时间: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);

            }

        });
    },
});

当然要根据实际情况更改一些相应的代码啦~~~!

猜你喜欢

转载自www.cnblogs.com/seesun2012/p/9214762.html