我有一个问题,即一个.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