0

我从 W3C School 获取了这段代码,它可以在 Ie 和 Chrome 上完美运行而无需更改,但是当我用我的 url 更改 'url' 参数时,它只适用于 Chrome 而不是 IE:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function loadXMLDoc(url)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    txt="<table border='1'><tr><th>Title</th><th>Artist</th></tr>";
    x=xmlhttp.responseXML.documentElement.getElementsByTagName("produits");
    for (i=0;i<x.length;i++)
      {
      txt=txt + "<tr>";
      xx=x[i].getElementsByTagName("produit");
        {
        try
          {
          txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
          }
        catch (er)
          {
          txt=txt + "<td> </td>";
          }
        }
      xx=x[i].getElementsByTagName("nomprod");
        {
        try
          {
          txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
          }
        catch (er)
          {
          txt=txt + "<td> </td>";
          }
        }
      txt=txt + "</tr>";
      }
    txt=txt + "</table>";
    document.getElementById('txtCDInfo').innerHTML=txt;
    }
  }
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="txtCDInfo">
<button onclick="loadXMLDoc('http://www.sosmalus.tm.fr/fexpat/webservices/choix_produits.php?dev_statut=1&dev_fdpaysid=AF&dev_fddeffet=2012-06-07&dev_fdnbadu=1&dev_fdnbenf=0&dev_fadnaiss_a_1=1952-06-19')">Get CD info</button>
</div>

</body>
</html>

你知道这有什么问题吗?谢谢!

PS:我已经<?php header("Access-Control-Allow-Origin: *"); ?>在远程页面中添加了

4

1 回答 1

0

我不认为 IE 在 IE10 之前支持 CORS。原始代码适用于 W3Schools 可能是因为它们的来源相同。

于 2012-06-13T14:49:15.650 回答