Webサービスは、はるかに高速であるため、私はこれを使用します。しかし、UpdatePanelsを使用している場合、Webサービスは役に立たない。私は、x秒ごとにページを更新するべきではないと言いますが、何かするための更新があれば、最初に尋ねます。これは多くを節約します;-)
これは少しの例かもしれませんが、私は試してみませんでしたが、このように一度働きました。 MSのAjaxのバージョンでは、クライアント側でのScriptManager
Type.registerNamespace("myproject");
myproject.updateControl = function() {
myproject.updateControl.initializeBase(this);
this._xhr = null;
this._updating = false;
this._timer = null;
}
myproject.updateControl.prototype = {
initialize: function() {
myproject.updateControl.callBaseMethod(this, 'initialize');
this.startTimer();
},
startTimer: function() {
if (this._timer) clearTimeout(this._timer);
this._timer = setInterval(Function.createDelegate(this, this._timerWork), 2000);
},
stopTimer: function() {
clearTimeout(this._timer);
this._timer = null;
},
_timerWork: function() {
if (this._updating || !this._checkXhr()) return;
this._xhr = Sys.Net.WebServiceProxy.invoke("myServicePath Or null if PageMethod", "checkForUpdate",
false,
null,
Function.createDelegate(this, this._onCheckedUpdate));
},
_onCheckedUpdate: function (data) {
this._xhr = null;
if (data.needsUpdate) {
this._update();
}
},
_udpate: function() {
if (!this._checkXhr) return;
this._updating = true;
this._xhr = Sys.Net.WebServiceProxy.invoke("servicepath", "updateMe", false, { param: param }, Function.createDelegate(this, this._updateSucces));
},
_updateSuccess: function (data) {
alert("yeah i´m get updated");
this._updating = false
this._xhr = null;
},
_checkXhr: function() {
if (this._xhr()) {
if (confirm("There is an active call to the Server. If you wait to long, it may have been broken. Do you want to Abort the current call?")) {
this._xhr.get_executor().abort();
this._xhr = null;
return true;
} else {
return false;
}
}
return true;
},
dispose: function() {
myproject.updateControl.callBaseMethod(this, 'dispose');
}
}
myproject.updateControl.registerClass('myproject.updateControl', Sys.Component);
使用を必要とする
$create(myproject.updateControl);
または
var upd = new myproject.updateControl();
upd.initialize();
おかげ。サーバー側では、私はレッスンを知っています。私はそこに頑張ります。それは私が少し心配しているクライアント側です。 +あなたはページにタイマーを実装するための提案はありますか? – Kamyar
JavaScriptのsetTimeoutを使用してタイマーを開始し、それぞれの応答が返ってから別のタイマーを再起動することができます。 'setTimeout(yourPollingFunction、2000)'は2秒間で 'yourPollingFunction'を呼び出します。代わりにsetIntervalを使用する誘惑を避けてください。それはいくつかの明白でない欠点を持っています:http://weblogs.asp.net/bleroy/archive/2009/05/14/setinterval-is-moderately-evil.aspx –
ありがとうDave。 – Kamyar