我试图使用jQuery get()
函数发出HTTP GET请求,但我遇到了一些麻烦。从jQuery发出GET请求的问题
这里是我的代码如下所示:
// get the links on the page
var pageLinks = $.find('#pageLinks');
// loop through each of the links
$(pageLinks).find('a').each(function(){
if($(this).attr('title') !== "Next Page"){
// make a GET request to the URL of this link
$.get($(this).attr("href"), function(data) {
console.log("here");
var temp = parse_page(data);
// concatenate the return string with another
bdy = bdy+String(temp);
console.log("done");
});
}
});
有迹象表明,我需要从获取数据的多个页面。由于get()
函数是异步的,我以随机顺序获取页面。其次,连接不起作用。尽管我得到了每一页,但它们并没有放入bdy
。
任何人都可以建议我怎么处理这个?
非常感谢!
'String(temp)'做了什么? – 2011-12-19 22:29:33
哪里是'bdy'定义? – muratgu 2011-12-19 22:31:22
就同步问题而言,为什么不使用jQuery推迟链接回调? – JesseBuesking 2011-12-19 22:35:03