我在 Firefox、android 操作系统和其他浏览器中运行时遇到问题。有谁知道为什么?我尝试了不同的解析,并且查看了一堆文档,包括https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest
function callNews()
{
var url = "someUrlHere";
var xmlhttp = new XMLHttpRequest();
var xmlDoc = null;
for (var i = 1; i < 20; i++)
{
xmlhttp.open("GET", url, false);
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlDoc = xmlhttp.responseXML;
var url2 = xmlDoc.getElementsByTagName("link")[i].textContent;
var newsTitle = xmlDoc.getElementsByTagName("title")[i].textContent;
var des = xmlDoc.getElementsByTagName("description")[i].textContent;
//var newsDate = xmlDoc.getElementsByTagName("pubDate")[i].textContent;
document.getElementById("desc" + i).innerHTML = newsTitle + "<br /><i style=\"color:red;\">" + des + "</i><br /><a href=\"" + url2 + "\">" + url2 + "</a>" + "<br /><br />" + "<iframe src=\"https://www.facebook.com/plugins/like.php?href=http://www.website.com\"scrolling=\"no\" frameborder=\"0\"style=\"border:none; width:450px; height:80px\"></iframe>";
xmlhttp.send();
}
document.getElementById("desc" + 1).innerHTML = "Testing";
}
更新了代码...仍然无法正常工作