我有一個問題,即一個.getJSON請求不拋出任何錯誤,或任何東西,它成功地進入回調函數(對我說的請求成功,是嗎?),但永遠不會退出。整個回調函數被執行,數據被正確讀取,但它永遠不會退出。.getJSON要求永遠不會退出
功能的getResult(選項){
console.log("inside getResult");
$.getJSON(yql, function(data){
console.log("inside getJSON");
var directions = '';
$(data.query.results.div).each(function(i,element){
htmlimg=(typeof(element.img) != 'undefined') ? '<img src="'+element.img.src+'" alt="'+element.img.alt+'">' : '';
switch(typeof(element.p)){
case 'undefined':
htmlp = '';
break;
case 'string':
if(element.p == 'Alternative routes:'){
//end looping
return false;
}
htmlp = '<p>' + element.p + '</p>';
break;
case 'object':
function showhtmlp(element){
var s = '';
if(typeof(element.content != 'undefined')){
s += element.content;
}
if(typeof(element.a) != 'undefined'){
s += element.a.content;
}
if(typeof(element.br) != 'undefined'){
s+='<br>';
}
return s
}
htmlp = '<p>';
if(typeof(element.p[0]) != 'undefined'){
$(element.p).each(function(i, data){
htmlp += showhtmlp(data);
});
} else {
htmlp += showhtmlp(element.p);
}
htmlp += '</p>';
break;
}
directions += '<div>'+htmlimg+htmlp+'</div>';
console.log("Directions: ");
console.log(directions);
});
console.log("OUT OF DIRECTIONS EACH FUNCTION/LOOP");
directions += '<div><a href="' + data.query.diagnostics.url.content + '" target="_blank" title="See on Google Maps"><img src="images/link.png" alt="Link" class="smallicon">View trip on Google Transit</a></div>';
console.log("step1");
trip.transit.routes[option].directions = directions;
console.log("step2");
$('#transitoption'+option).html(directions);
console.log("step3");
});//end of .getJSON
console.log("out of JSON");
}//end of getResult?
console.log("out of Result");
getResult(option);
的 「結束之前」 打印出所述的console.log命令。沒有錯誤被拋出。但是,它永遠不會到達「out of JSON」的console.log。
當我試圖使用控制檯進行調試時,我發現它陷入了jquery.min.js代碼的一部分,儘管它最小化了,但我可以告訴它有「abort」和「timeout」這樣的詞。
我是比較新的Ajax請求,所以請非常具體。
的YQL變量是:
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fmaps.google.com%2Fm%2Fdirections%3Fsaddr%3D37.78414%2C%2B-122.44108%26daddr%3D37.61688%2C%2B-122.38400999999999%26dirflg%3Dr%26ri%3D0%26date%3D2011-09-02%26time%3D9%3A21pm%22%20and%20xpath%3D'%2F%2Fdiv%2Fdiv'&format=json&diagnostics=true
有一點要記住的是,你不應該期待讀取從上往下。 getJSON方法將執行,將「應該」記錄「out of JSON」,並且稍後在請求完成後,回調纔會運行。 – evan
你能顯示* YQL * – naveen
的YQL變量現在張貼以上。 – dlitwak