我必须每10分钟更新一次网络服务,我尝试使用setInterval它不适合我。 这是我的代码,
onActivate:function()
{
setInterval(onActivate(),6000);
Ext.Ajax.request({
method:'GET',
contentType:'application/json; charset=utf-8',
dataType:'json',
url:'myurl',
//timeout:6000,
disableCaching: false,
interval:6000,
reader: {
type: 'json',
totalProperty: 'totalcount',
rootProperty:'GetMobileOperatorListResult',
},
success:function(response,request)
{
var jsonarr = Ext.decode(response.responseText);
var len=jsonarr.GetMobileOperatorListResult.length;
console.log("length"+len);
for(var i=0;i<len;i++)
{
//Storing our values in Array
var st = {
'text':jsonarr.GetMobileOperatorListResult[i].Operator,
'value':jsonarr.GetMobileOperatorListResult[i].OperatorValue,
};
//Adding our array to LocalStore(localStorage)
var localStore = Ext.getStore('MobileStore');
localStore.add(st);
localStore.sync();
localStore.load();
}//for loop
console.log("operator value\t"+st.value);
localStore.getProxy().clear();
},
答案 0 :(得分:1)
查看ExtJS轮询提供商
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.direct.PollingProvider
var poll = new Ext.direct.PollingProvider({
type: 'polling',
url: function () {
Ext.Ajax.request({
url: 'myurl',
qualifier: 'Keep Alive',
success: function (xhr) {
//do your data processing here
},
failure: function () {
}
});
},
interval: 6000
});
Ext.Direct.addProvider(poll);