XMLHttpRequest cannot load Cross origin requests are only supported for HTTP

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

found an exception 101 in getting data from XML file:XMLHttpRequest cannot load file:///C:/Users/zaid/Desktop/xml/cd_catalog.xml. Cross origin requests are only supported for HTTP.

<script type="text/javascript"> 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","xml/cd_catalog.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML;   document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("CD"); for (i=0;i<x.length;i++)   {    document.write("<tr><td>");   document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);   document.write("</td><td>");   document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);   document.write("</td></tr>");   } document.write("</table>"); </script> 

回答1:

You're trying to request a resource through your local machine, that's a cross reference. You need to access to this resource trough your HTTP server to get access to it.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!