is it possible to request more than 1 Feed at the same time?
for example
google.load("feeds", "1",{"callback" : 'get_it(\'http://
www.fernsehkritik.tv/?feed=podcast\',\'1\'),get_it(\'http://rss.golem.de/rss.php?feed=RSS1.0\',\'99\')'});
or ...
google.load("feeds", "1",{"callback" : 'get_it(\'http://
www.fernsehkritik.tv/?feed=podcast\',\'99\')'});
google.load("feeds", "1",{"callback" : 'get_it(\'http://rss.golem.de/
rss.php?feed=RSS1.0\',\'99\')'});
Both solutions are working but i am not sure, is this the right (clean) way?
Thanks in adv开发者_如何学Goance! Peter
So I think you're a slight bit confused at to what's going on. When you call google.load("feeds", "1",{"callback": "get_it('http://myfeed.com/whatever')"})
, you're not requesting that Google go load the feed at http://myfeed.com/whatever
. What you're saying is: "Hey, Google, load up the javascript to support your feed api, and when your feed api is all loaded and ready to use, call get_it('http://myfeed.com/whatever')
, where presumably get_it
is a function you've defined already in your page that uses Google's feed api to do its thing.
So I think your purpose would be better served by defining a single javascript function to execute one the feed is ready, something like:
function feed_api_ready() {
get_it('http://www.fernsehkritik.tv/?feed=podcast', '99');
get_it('http://rss.golem.de/rss.php?feed=RSS1.0', '99');
}
And then calling simply:
google.load("feeds", "1",{"callback" : 'feed_api_ready'})
That'll execute both "go get the feeds" functions right away when the Google API is all loaded.
Now, as for getting the feeds in parallel: believe it or not, that will also load the feeds in parallel. Javascript doesn't really have any ability to block and wait on network I/O, so anything in javascript that gets stuff from the network always has to be written in the form: "Go make this network request, and here's a function to call when you eventually get a response". But in the meantime, the javascript engine on the browser keeps going without waiting for the response to come back.
This means that above, you'll fire off the request for http://www.fernsehkritik.tv/?feed=podcast
and your browser will continue executing javascript without waiting for the network to respond, and you'll fire off the second request for http://rss.golem.de/rss.php?feed=RSS1.0
. So the network traffic for both feeds will then be coming back to your browser in parallel, even though javascript in the browser doesn't allow multiple threads of execution.
精彩评论