Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用get和parse xml发送信息_Javascript_Html_Xml_Xml Parsing_Get - Fatal编程技术网

Javascript 使用get和parse xml发送信息

Javascript 使用get和parse xml发送信息,javascript,html,xml,xml-parsing,get,Javascript,Html,Xml,Xml Parsing,Get,我编写了一个使用XML文件的简单代码。如果我使用以.xml结尾的链接,它将正常工作。但是当我改变了与的链接时,它显示了任何东西 我的代码如下 我怎样才能解决这个问题 <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head> <body> <script> if (wind

我编写了一个使用XML文件的简单代码。如果我使用以.xml结尾的链接,它将正常工作。但是当我改变了与的链接时,它显示了任何东西

我的代码如下

我怎样才能解决这个问题

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>

    <script>
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.open("GET", "http://www.tbl.org.tr/xml.asp?Lig=Beko&Eylem=PD&sezon=2013-2014", false);
        xmlhttp.send();
        xmlDoc = xmlhttp.responseXML;

        document.write("<table width='350' cellpadding='5'>");
        var x = xmlDoc.getElementsByTagName("Siralama");
        document.write("<tr><td width='20'>");
        document.write("Sıra");
        document.write("</td><td width='290'>");
        document.write("Takım");
        document.write("</td><td width='20'>");
        document.write("O");
        document.write("</td><td width='20'>");
        document.write("G");
        for ( i = 0; i < 8; i++) {
            document.write("<tr><td width='20'>");
            document.write(x[i].getAttribute('Sira'));
            document.write("</td><td width='290'>");
            var y = x[i].getAttribute('Takim');
            if (y.length == 15)
                document.write("<font color=red><b>" + x[i].getAttribute('Takim') + "</b></font>");
            else
                document.write(x[i].getAttribute('Takim'));
            document.write("</td><td width='20'>");
            document.write(x[i].getAttribute('O'));
            document.write("</td><td width='20'>");
            document.write(x[i].getAttribute('G'));

            document.write("</td></tr>");
        }
        document.write("</table>");
    </script>

</body>

if(window.XMLHttpRequest){//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}else{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
open(“GET”http://www.tbl.org.tr/xml.asp?Lig=Beko&Eylem=PD&sezon=2013-2014年”,假);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
文件。填写(“”);
var x=xmlDoc.getElementsByTagName(“Siralama”);
文件。填写(“”);
文件。书写(“Sıra”);
文件。填写(“”);
文件。书写(“Takım”);
文件。填写(“”);
文件。填写(“O”);
文件。填写(“”);
文件。填写(“G”);
对于(i=0;i<8;i++){
文件。填写(“”);
document.write(x[i].getAttribute('Sira');
文件。填写(“”);
变量y=x[i].getAttribute('Takim');
如果(y.长度==15)
document.write(“+x[i].getAttribute('Takim')+”);
其他的
document.write(x[i].getAttribute('Takim');
文件。填写(“”);
document.write(x[i].getAttribute('O');
文件。填写(“”);
document.write(x[i].getAttribute('G');
文件。填写(“”);
}
文件。填写(“”);

由于我没有足够的声誉发表评论,我不得不回答这个问题。
您的问题很可能是由“访问控制允许来源”引起的。我认为查理所说的是真的。我只想补充一点,您可能会考虑使用文档以外的其他东西。作为文档编写。写允许您从XML加载站点来操作您的网站并注入自定义脚本。您应该解析代码并创建DOM元素,而不是将它们写入文档。

什么是
解析链接
?我们不叫它们解析链接吗?如果没有,对不起。我的意思在上面。我看到了xml…但仍然不能解释您的问题…或者您正在更改的内容导致代码失败,也不能解释如果我使用domain.com/abc.xml代码,解析链接是什么。当我使用它时,它不起作用。这是一个跨域调用…用ajax和xml无法做到这一点。必须以jsonp的形式获取数据(如果其他域提供),或者在服务器上使用代理来获取xml