从存在的问题做jQuery的GET请求 [英] Problems making GET request from jQuery
问题描述
我试图让使用jQuery 的get()
功能的HTTP GET请求,但我遇到了一些麻烦。
I'm trying to make an HTTP GET request using the jQuery get()
function, but I'm having some trouble.
下面是我的code样子:
Here's what my code looks like:
// 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
。
There are multiple pages that I need to get data from. Since the get()
function is asynchronous, I get the pages in a random order. Secondly, the concatenation does not work. Even though I get each of the pages, they're not put into bdy
.
任何人都可以建议我怎么可以处理这个问题?
Can anyone suggest how I might deal with this?
非常感谢!
推荐答案
我只是发现有模块,允许一个管理JS控制流。我发现的是:
I just found that there are modules that allow one to manage the control flow in JS. The ones I found are:
- Async
- Step
有关使用上述模块的帮助,请参阅我的跟进质询,<一个href=\"http://stackoverflow.com/questions/8810825/using-async-parallel-along-with-javascript\">here.
For help using the above modules, see my follow up question here.
这篇关于从存在的问题做jQuery的GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!