0
我有一個用於請求報告的網頁。當用戶點擊一個按鈕時,我正在調用一個函數,它會發出一個ajax請求來處理這些報告。一旦請求完成,我使用setInterval函數每隔1秒檢查報告的狀態(是否完成)。一些如何,setInterval()中的函數根本不被調用。從ajax成功遞歸調用另一個ajax函數
以下是JavaScript代碼,我有
var GLFiles_JSObject = {
url: "<%= Request.ApplicationPath %>/AjaxRequest.aspx",
apppath: '<%= Request.ApplicationPath %>',
btnRefreshId: '<%= btnRefresh.ClientID %>',
ajaxFunctionName: 'GLBuilder_ReprocessFiles',
reportstatusFuncName: 'GLBuilder_GetReportStatus',
reportid: 0,
ajaxError: function(XMLHttpRequest, textStatus, errorThrown){
alert(XMLHttpRequest.statusText);
},
ajaxSuccess: function(msg) {
if (msg === '') {
setInterval(function(){
this.reportstatus();
}, 1000);
}
},
reportstatusSuccess : function(msg) {
if (msg === '1') {
clearInterval();
}
},
reportstatus : function() {
var keys = new Array('reportid');
var values = new Array(reportid);
//ajax call
WebServicePost(true, this.url, this.reportstatusFuncName, keys, values, this.ajaxError, this.reportstatusSuccess);
}
};
//this will be called when button is clicked.
function reprocessGLFiles(reportid, btnid) {
//disable the button
//$('#' + btnid).attr("disabled", true);
GLFiles_JSObject.reportid = reportid;
var keys = new Array('reportid');
var values = new Array(GLFiles_JSObject.reportid);
// make an ajax request to process the files
WebServicePost(true, GLFiles_JSObject.url, GLFiles_JSObject.ajaxFunctionName, keys, values, GLFiles_JSObject.ajaxError, GLFiles_JSObject.ajaxSuccess);
return false;
}
當我要求報告時,系統會將狀態更新爲等待狀態。然後有一個窗口服務提取等待記錄並處理報告。所以,我想查詢數據庫來檢查報告是否被處理。當它們處理完畢後,我將刷新頁面並添加新的報告。 – Sridhar 2011-05-24 14:06:14