嗨,我们一直试图解决这个问题在过去的几个小时,并决定ID在这里睡觉之前把它放在这里,无论如何,问题是我需要确保GET/POST请求在继续执行代码之前已经100%处理完毕,我用firefox addon sdk中的定时器解决了这个问题,但是因为这是java脚本,它锁定了UI,所以我一直在寻找解决方案我偶然发现了Felix Kling的一个潜在解决方案,“How do I return the response from an asynchronous call?”。尽管我尝试过没有成功,所以我想知道如果有人能告诉我什么是我做错了,或者如果我甚至不能使用这个解决方案来做我想做的事情。在继续之前确保异步GET/POST请求已完成
download_status(download_database());
function download_status(downloadStatus){
if(downloadStatus==0){
console.log(regexArray.length);
}
else{
console.log("oh no");
}
}
function download_database(){
var downloadDone = 0;
var requestDB = request.Request({
url: "http://phyzical.pythonanywhere.com/download_db/",
onComplete: function(response){
console.log(response.statusText);
if(response.json == null){
console.log("cannot retreive json properly.")
}
else{
var dbInfoLength = response.json.length;
var idNumber = 0;
for(var x=0;x<dbInfoLength;x++){
try{
var patt1=new RegExp(response.json[x].regex);
idArray[idNumber] = response.json[x].id;
regexArray[idNumber] = response.json[x].regex;
incorrectMessageArray[idNumber] = response.json[x].incorrect_information;
correctMessageArray[idNumber] = response.json[x].correct_information;
idNumber++;
}
catch(e){
console.log("The annotation with the id: \""+ response.json[x].id+" " + e.message + "\" is wrong.");
}
}
downloadDone = 0;
}
},
}).get();
return downloadDone;
}
黯然regexArray.length日志从一开始的“0”,然后“确定”,然后将捕获的火灾之一,所以我知道的信息被存储到阵列简单,同样的问题我开始仍然存在。
任何帮助,将不胜感激。
您链接的帖子 - 非常清楚地解释它的一切。你需要使用回调。 – webduvet