世論調査サポートしているサーバのデザイン道場
-
20-09-2019 - |
質問
を使用してい 道場があります。xhrPost を送信Ajaxの要求
通話に包まれる function sendRequest()
私は現在継続的に毎3sec)で送と同じajax郵便のサーバー
たいのですが実施するサーバーの投票と道?については基本的に電話をする必要があり sendRequest()
毎3秒
解決
私はので、ここでフレームワーク全体で適用だジェネリックメソッドですが、道場は、組み込みのポーリングのための方法を持っていることを信じていません。
var Poll = function(pollFunction, intervalTime) {
var intervalId = null;
this.start = function(newPollFunction, newIntervalTime) {
pollFunction = newPollFunction || pollFunction;
intervalTime = newIntervalTime || intervalTime;
if ( intervalId ) {
this.stop();
}
intervalId = setInterval(pollFunction, intervalTime);
};
this.stop = function() {
clearInterval(intervalId);
};
};
使用方法:
var p = new Poll(function() { console.log("hi!"); }, 1000);
p.start();
setTimeout(function() { p.stop();}, 5000);
またはあなたの場合:
var p = new Poll(sendRequest, 3000);
p.start();
あなたは道場パッケージとしてこれをしたい場合は、、その後、次のように些細な拡張機能です。
dojo.provide("Poll");
dojo.declare("Poll", null, {
intervalId: null,
pollFunction: null,
intervalTime: null,
constructor: function(newPollFunction, newIntervalTime) {
this.pollFunction = newPollFunction;
this.intervalTime = newIntervalTime;
},
start: function(newPollFunction, newIntervalTime) {
this.pollFunction = newPollFunction || this.pollFunction;
this.intervalTime = newIntervalTime || this.intervalTime;
this.stop();
this.intervalId = setInterval(this.pollFunction, this.intervalTime);
},
stop: function() {
clearInterval(this.intervalId);
}
});
使用方法:
var p = new Poll(function() {console.log("hi");}, 250);
p.start();
setTimeout(dojo.hitch(p, p.stop), 1000);
他のヒント
いよいようになります:
- いての変数が含まれ、空の配列(キュー)
- setIntervalる世論調査に関する世論調査で、新しいオブジェクトの調査パラメータの配列(キュー);また、圧縮世論調査による崩壊のオブジェクトと同じパラメーターを単一のオブジェクト;きもを入れてハンドラの機能をこれらのオブジェクト
- してタイマーの検査キューの先頭;ない場合を返す
- がある場合は申請中のオブジェクトのキューがあるかどうかをチェックします既出願中のxhr操作が返されませんでお待ち--いくxhr未同時に、一部の機器(例えばiPad)chokesで
- がない場合は申請中xhr操作dequeue最初のクオブジェクトxhrGetで
この手続きができるのが簡単にスロットル調査間隔で動作する場合xhr業間で容易に行えますの民営化のポーリングします。
継続的にあなたのグリッドを更新するには、あなたはグリッドの「リフレッシュ完了」のコールバック関数では、あなたのAJAXリクエストを含めることができます。
yourGrid.on('dgrid-refresh-complete', function(event) {
//Ajax request fireing every 3 sec
}
所属していません StackOverflow