代理问题这是我的javascript函数,它抓住通过代理脚本的RSS提要,然后吐出来从进料5个最新的RSS项目并链接到我的样式表一起:使用JavaScript跨域RSS订阅解析
function getWidget (feed,limit) { if (window.XMLHttpRequest) {
xhttp=new XMLHttpRequest()
} else {
xhttp=new ActiveXObject("Microsoft.XMLHTTP")
}
xhttp.open("GET","http://MYSITE/proxy.php?url="+feed,false);
xhttp.send("");
xmlDoc=xhttp.responseXML;
var x = 1;
var div = document.getElementById("div");
div.innerHTML = '<link type="text/css" href="http://MYSITE/css/widget.css" rel="stylesheet" /><div id="rss-title"></div></h3><div id="items"></div><br /><br /><a href="http://MYSITE">Powered by MYSITE</a>';
document.body.appendChild(div);
content=xmlDoc.getElementsByTagName("title");
thelink=xmlDoc.getElementsByTagName("link");
document.getElementByTagName("rss-title").innerHTML += content[0].childNodes[0].nodeValue;
for (x=1;x<=limit;srx++) {
y=x;
y--;
var theitem = '<div class="item"><a href="'+thelink[y].childNodes[0].nodeValue+'">'+content[x].childNodes[0].nodeValue+'</a></div>';
document.getElementById("items").innerHTML += theitem;
} }
这里是proxy.php的代码:
$session = curl_init($_GET['url']); // Open the Curl session
curl_setopt($session, CURLOPT_HEADER, false); // Don't return HTTP headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Do return the contents of the call
$xml = curl_exec($session); // Make the call
header("Content-Type: text/xml"); // Set the content type appropriately
echo $xml; // Spit out the xml
curl_close($session); // And close the session
现在,当我尝试加载此上,这不是我的网站没有任何负载域。我没有JS错误,但我在萤火虫控制台选项卡我得到“407代理验证必需”
所以我不知道如何使这项工作。
目标是能够获取RSS提要,解析它以获取标题和链接,并将其吐出到Web上任何网站上的某些HTML中。我的“M基本上是让我的网站的各种RSS一个简单的RSS提要部件。
我的JavaScript是怪人
我真的使用Javascript初学者。我知道jQuery的非常好,但我不能够在这种情况下使用它,因为这个脚本将嵌入任何网站,我不能真正依赖于jQuery库,所以我决定写一些基本的JavaScript依赖于默认的XML解析选项。谢谢!
什么是x和y变种
他们的方式我的网站创建RSS源是第一个标题实际上是RSS源标题。第二个标题是第一个项目的标题。第一个链接是第一个项目的链接。所以当使用javascript来获得标题时,我必须首先获取第一个标题(这是RSS标题),然后从第二个标题开始,该标题是该项目的第一个标题。对不起,我感到困惑,但我不认为这与我的问题有关。只是想澄清我的代码。
谢谢。我正在尝试这个,但我怎么解析它以获取每个项目的标题和链接? – Amir 2010-04-21 04:00:00
没关系我想通了。非常感谢! – Amir 2010-04-21 04:56:35
对不起,我可能应该提供一个更好的例子来说明如何对数据对象做些什么。更新。 – 2010-04-21 17:45:52