The previous time project, need front-end JS get cross-domain XML (RSS), first intend to use the Jquery.ajax method to obtain, but under IE9, hint "denied access" slightly embarrassed, online search related data summarized the following methods:
One, Google's jgfeed: I believe that many students should not unfamiliar to this, the use is relatively simple:
Source:
(function ($) {
$.extend ({
jgfeed:function (URL, fnk, num, key) {
//Make sure URLs to get are defined
if (url = = null) return false;
Build Google Feed API URL
var gurl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?" &q= "+url;
if (num!= null) Gurl + = "&num=" +num;
if (key!= null) Gurl + = "&key=" +key;
AJAX request the API
$.getjson (gurl, function (data) {
if (typeof fnk = = ' function ')
fnk.call (This, Data.responseData.feed);
else return
false;});}
(JQuery);
Call:
Jquery.jgfeed (' XML or RSS path ', function (feeds) {
console.log (feeds);
})
Second, Yahoo's yql query; this way may be some students do not know much, and do not say please look down:
var yqlurl= ' http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3d ' +xml or RSS path + ' &format=json&diagnostics=true&callback=? '
$.getjson (yqlurl,function (data) {
console.log (data)
})
The above yqlurl is the Yahoo YQL console to copy down, as long as oneself replaces the corresponding file path.
Here is a recommended Yahoo yql control address, there are a lot of fun things (get weather, Woeid, cross-domain data, etc.), you can return XML and JSON two of results.
The above jquery get cross domain XML (RSS) data related summary analysis is small series to share all the content, hope to give you a reference, also hope that we support cloud habitat community.