2
我有實現與Ext.Ajax.request)彗星溶液(以使得當發生超時或一個成功的響應已被接收則相同的請求被重新初始化。更新模型,並存儲在分機JS與彗星長輪詢
var http = {
requestId: 0,
request: function(timeout){
Ext.Ajax.request({
url: '/echo/json/',
timeout: timeout || 10000,
method: 'POST',
scope: http, // scoped to the http object
params: {
json: Ext.encode({
data: [
{
id: 1,
type: 'notification',
timestamp: Ext.Date.format(new Date(), 'timestamp'),
from: 1445261,
to: 1402804,
read: false,
important: true,
content: 'Lorem ipsum...'
}
]
}),
delay: 5
},
success: function(resp) {
if (resp.status === 200){
console.log('success');
this.request();
}
},
failure: function(resp, opts) {
if (resp.timedout === true) {
console.log('failure');
this.request();
} else {
}
},
callback: function(options, success, resp) {
if (this.requestId === 0) {
this.requestId = resp.requestId;
}
}
});
}
};
http.request();
我想Ext JS的MVC中實現這一點,並利用本地代理從服務器獲取數據,並將其加載到通過模型的商店。
望着文檔我看不出如何可以做到這一點,你似乎並沒有能夠獲得成功和失敗回調作爲Ext.Ajax.request方法。
有誰知道如何實現長輪詢與分機MVC架構?
上面的示例代碼利用回聲的jsfiddle AJAX JSON響應:
選項3不會導致商店永久處於裝載狀態嗎?如果調用store.load(),則打開一個長數據連接isLoading將始終爲真,然後會導致關聯視圖的加載掩碼處於打開狀態。 – RyanP13
是的,你說得對有關 - 但你可以禁用的加載面具和覆蓋任何其它不良的副作用,如果有不太多 - 我還沒有嘗試過這一點,但它是值得一試。 – dbrin