在下面的代码中,最初在页面加载时,执行完整块。但是在页面加载后,只有else条件被执行。为什么?
请在下面找到完整的代码。
unction verifyrequestArray(id) {
console.log("in verifyrequestarray" + requestArray.length);
var y = true;
//requestArray=["1012-abc","2089-xyz","1012-abc"];
var tempArr = [];
//for removing duplicates in the array
for (i = 0; i < requestArray.length; i++) {
if (tempArr.indexOf(requestArray[i]) == -1) {
tempArr.push(requestArray[i]);
}
}
//alert(tempArr);
//verify if the value already exists
for (j = 0; j < tempArr.length; j++) {
if (tempArr.hasOwnProperty(id)) {
console.log("req id already present in array");
break;
} else {
console.log("req id not present in array");
return false;
}
}
}
function getStatusfromArray(id) {
console.log("in get status");
requestStatus = requestArray.hasOwnProperty(id);
console.log("status for " + id + ":" + requestStatus);
return requestStatus;
}
function setTooltip(currentTag, status) {
console.log("in settooltip" + currentTag);
currentTag.attr("title", status); //setting status a tooltip
}
function getStatusUsingAjax(requestValue, callback) {
console.log("inside function getStatusUsingAjax");
var currentStatus;
GM_xmlhttpRequest({
method: "GET",
url: link,
async: false,
onload: function(response) {
if ($(response.responseText).find("#P16_STATUS2").size() === 1) {
currentStatus = $(response.responseText).find("#P16_STATUS2").text();
console.log("Status is " + currentStatus);
} else if ($(response.responseText).find("#P16_STATUS3").size() === 1) {
currentStatus = $(response.responseText).find("#P16_STATUS3").val();
console.log("Status is " + currentStatus);
}
var pusharr2 = [requestValue + "-" + currentStatus];
requestArray.push(pusharr2);
//console.log("Updated Array is "+requestArray);
callback(currentStatus);
}
});
}
function loadStatus(x) {
$('.a-IRR-table tr').each(function(i) {
var val = $(this).find("td").eq(0).text();
if ((val !== "-") && (val !== "")) {
link = $(this).find("td").eq(0).find("a").attr("href");
linkTag = $(this).find("td").eq(0).find("a");
console.log("Link Tag is " + linkTag);
console.log("val is " + val);
var x = verifyrequestArray(val);
console.log("x is " + x);
if (verifyrequestArray(val)) {
var updatedStatus = getStatusfromArray(val);
setTooltip(linkTag, updatedStatus);
} else {
console.log("in else");
//var updatedStatus2=getStatusUsingAjax(val);
getStatusUsingAjax(val, function(updatedStatus2) {
console.log("UpdatedStatus2 is " + updatedStatus2);
console.log("Link Tag is " + linkTag);
setTooltip(linkTag, updatedStatus2);
});
sleep(1.5 * 1000);
}
}
});
}