У меня есть веб-страница, которая используется для запроса отчетов.Когда пользователь нажимает кнопку, я вызываю функцию, которая сделает запрос ajax для обработки отчетов.Как только запрос сделан, я использую функцию setInterval для проверки состояния отчета (независимо от того, заполнен он или нет) каждую 1 секунду.Так или иначе, функция внутри setInterval () не вызывается вообще.
Ниже приведен код 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;
}