gpt4 book ai didi

Javascript 不能在除 IE 之外的任何其他浏览器中运行。为什么?

转载 作者:行者123 更新时间:2023-11-28 02:20:30 24 4
gpt4 key购买 nike

我在使其在 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";
}

更新了代码...仍然不起作用

最佳答案

这对我来说效果更好

function callNews()
{
var url = "urlGoesHere";

if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
alert("Old");
}
xmlhttp.open("GET", url, false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
var x = xmlDoc.getElementsByTagName("title");
var d = document.createElement("div");
var news = new Array();
var word = "";
for (var i = 0; i < x.length; i++)
{
news[i] = "<a href=\"" + xmlDoc.getElementsByTagName("link")[i].childNodes[0].nodeValue + "\" style=\"text-decoration:none;\" >" + xmlDoc.getElementsByTagName("title")[i].childNodes[0].nodeValue + "</a>";
news[i] = "<b>" + news[i] + "</b><br /><em style=color:#555;> " + xmlDoc.getElementsByTagName("description")[i].childNodes[0].nodeValue + "</em>";
word = word + " " + news[i] + "<br /><br />"
}
document.getElementById("newsUpdate0").innerHTML = word;
}

关于Javascript 不能在除 IE 之外的任何其他浏览器中运行。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15732822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com