我在自动刷新方法中有一个方法。它正在进行AJAX调用。我的要求是我必须执行n
个请求并同时显示结果,因此我有一个执行请求的方法和一个用于显示结果的方法。
显示结果的方法在自动刷新方法中。但我的问题是我的auto_Refresh
方法被阻止,除非所有请求都已完成并返回最终结果。我想异步显示结果。我的代码工作到上周。我不知道突然发生了什么事以防止它起作用。有人能为我提供解决方案吗?
// setting the refresh interval and calling execute method.
setRefreshInterval();
executeDeployment();
//My Execute method
function executeDeployment() {
try {
$.ajax({
url: "/Release/ExecuteCommandDemo",
type: "Post",
contentType: "application/json; charset=utf-8",
data: '{DeploymentId:"' + DeploymentId + '",iswebapicall:"' + iswebapicall + '"}',
dataType: "json",
success: function (data) {
try {
var result = data;
var finalStatus = data[0].FinalStatus;
} catch (ex) {
LogEvent("LogRelease.executeDeployment", ex.message);
}
},
error: function (msg)
});
} catch (ex) {
LogEvent("LogRelease.executeDeployment", ex.message);
}
}
//my refresh method
function AutoRefresh() {
getDeploymentStatus(DeploymentId, ProjectId, true);
}
// getDeploymentStatus method
try {
var timeZoneOffset = new Date().getTimezoneOffset();
$.ajax({
url: "/Release/getDeploymentStatus",
type: "Post",
contentType: "application/json; charset=utf-8",
data: '{DeploymentId:"' + DeploymentId + '",ProjectId:"' + ProjectId + '"}',
dataType: "json",
async: false,
success: function (res) {
try {....
}
我已将刷新间隔设置为1000毫秒,但除非完成执行,否则我的GetdeploymentStatus
仍未执行。我的意思是说自动刷新方法在某种程度上被阻止,并且在指定的时间间隔后没有被调用。
//GetDeploymentStatus Method
function getDeploymentStatus(DeploymentId, ProjectId,freshRequest)
{
try {
var timeZoneOffset = new Date().getTimezoneOffset();
$.ajax({
url: "/Release/getDeploymentStatus",
type: "Post",
contentType: "application/json; charset=utf-8",
data: '{DeploymentId:"' + DeploymentId + '",ProjectId:"' + ProjectId + '",timeZoneOffset:"' + timeZoneOffset + '"}',
dataType: "json",
async:false,
success: function (res) {
try {
$('#dynamicOutput').html("");
//if (freshRequest) {
// var resultStatus = "Requested";
// $('#resStatus').text(resultStatus);
//}
if (res != "") {
if (res[0].deploymentStatus == "Scheduled") {
$('#resStatus').css("color", "black");
}
if (res[0].deploymentStatus == "Succeeded") {
$('#resStatus').css("color", "green");
}
else {
$('#resStatus').css("color", "red");
}
$('#resStatus').text(res[0].deploymentStatus);
//$('#lblDeploymentName').text(res[0].deploymentName);
//$('#lblEnvName').text(res[0].EnvName);
var data = res;
$.each(data, function (index) {
//debugger;
$('#stopdeployment').hide();
if (res[0].StepStatus == "Stopped") {
$('#resStatus').text("Stopped");
testStr = '<div class="panel-heading"><div class="form-group"><label> Package ID :' + data[index].PackageId + '</label><br /></div><div class="form-group"><label> Step name :' + data[index].StepName + ' Step Details : ' + data[index].StepDetails + '</label><br /></div><div class="panel panel-body"><div class="form-group">' + data[index].StepStartTime + '<br />' + res[index].StepOutput + '<br />' + '<br />' + '<label style="color:orange">' + res[index].StepStatus + '</label>' + '<br />' + data[index].StepEndTime + '</div></div></div>';
$('#dynamicOutput').append(testStr);
$('#dynamicOutput').show();
}
if (res[0].StepStatus == "Succeeded") {
testStr = '<div class="panel-heading"><div class="form-group"><label> Package ID :' + data[index].PackageId + '</label><br /></div><div class="form-group"><label> Step name :' + data[index].StepName + ' Step Details : ' + data[index].StepDetails + '</label><br /></div><div class="panel panel-body"><div class="form-group">' + data[index].StepStartTime + '<br />' + res[index].StepOutput + '<br />' + '<label style="color:green">' + res[index].StepStatus + '</label>' + '<br />' + data[index].StepEndTime + '</div></div></div>';
$('#dynamicOutput').append(testStr);
$('#dynamicOutput').show();
}
else if (res[0].StepStatus == "Failed") {
testStr = '<div class="panel-heading"><div class="form-group"><label> Package ID :' + data[index].PackageId + '</label><br /></div><div class="form-group"><label> Step name :' + data[index].StepName + ' Step Details : ' + data[index].StepDetails + '</label><br /></div><div class="panel panel-body"><div class="form-group">' + data[index].StepStartTime + '<br />' + res[index].StepOutput + '<br />' + '<label style="color:red">' + res[index].StepStatus + '</label>' + '<br />' + data[index].StepEndTime + '</div></div></div>';
$('#dynamicOutput').append(testStr);
$('#dynamicOutput').show();
}
});
}
}
catch (ex)
{ LogEvent("LogRelease.getDeploymentStatus", ex.message); }
},
error:function(msg)
{ alert("Error while View Log Release. Please contact to administrator"); }
});
}
catch (ex)
{ LogEvent("LogRelease.getDeploymentStatus", ex.message); }
}