Ext.Ajax.request() を使用して Comet ソリューションを実装したので、タイムアウトが発生したとき、または成功した応答が受信されたときに、同じ要求が再初期化されます。
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 メソッドのように成功および失敗のコールバックにアクセスできないように見えるため、これを行う方法がわかりません。
Ext MVC アーキテクチャでロングポーリングを実装する方法を知っている人はいますか?
上記のコード例では、JSFiddle ajax JSON 応答エコーを利用しています。