Problem retrieving rss fields using jquery
I'm not sure what is going on here. I'm trying to pull a public rss feed using jquery and an ajax request. Here is the code snipet. Feel free to try the url to help.
Using firebug I can see the request going out. I receive a 200 Ok from the server but the开发者_高级运维 response is blank.
$.ajax({
type: "GET",
url: "http://www.andersen-const.com/news-events?view=newsevents&task=view&type=news&id=99",
dataType: "xml",
success: function(xml) {
$(xml).find('article-content').each(function() {
var heading = $(this).find('h3').text();
$('<div class="items" id="link_'+count+'"></div>').appendTo('#news_canvas');
count = count + 1;
});
}
});
You are not allowed to to just pull in an XML feed from another domain because of the cross origin policy in browsers. Further, that link is not an XML feed, it it just a plain website.
What you are looking to do it scrape the contents of a page and pull them in. You can do this with yahoo's YQL which offeres a serverside later inbetween you and the website.
Here is a link to get you started with the #articleContent div already picked out:
http://developer.yahoo.com/yql/console/#h=SELECT%20*%20FROM%20html%20WHERE%20url%3D%22http%3A//www.andersen-const.com/news-events%3Fview%3Dnewsevents%26task%3Dview%26type%3Dnews%26id%3D99%22%20AND%20xpath%3D%22//div%5B@class%3D%27article-content%27%5D%22
精彩评论