Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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 无法加载XMLHttpRequesthttp://localhost:8081/sample.xml. 访问控制允许原点不允许原点为null。 函数loadXMLDoc(url) { var-xmlhttp; 变量txt,x,xx,i; if(window.XMLHttpRequest) {//IE7+、Firefox、Chrome、Opera、Safari的代码 xmlhttp=新的XMLHttpRequest(); } 其他的 {//IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } xmlhttp.onreadystatechange=函数() { if(xmlhttp.readyState==4&&xmlhttp.status==200) { txt=“AuthorTitle”; x=xmlhttp.responseXML.documentElement.getElementsByTagName(“书”); 对于(i=0;i_Javascript_Iis - Fatal编程技术网

Javascript 无法加载XMLHttpRequesthttp://localhost:8081/sample.xml. 访问控制允许原点不允许原点为null。 函数loadXMLDoc(url) { var-xmlhttp; 变量txt,x,xx,i; if(window.XMLHttpRequest) {//IE7+、Firefox、Chrome、Opera、Safari的代码 xmlhttp=新的XMLHttpRequest(); } 其他的 {//IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } xmlhttp.onreadystatechange=函数() { if(xmlhttp.readyState==4&&xmlhttp.status==200) { txt=“AuthorTitle”; x=xmlhttp.responseXML.documentElement.getElementsByTagName(“书”); 对于(i=0;i

Javascript 无法加载XMLHttpRequesthttp://localhost:8081/sample.xml. 访问控制允许原点不允许原点为null。 函数loadXMLDoc(url) { var-xmlhttp; 变量txt,x,xx,i; if(window.XMLHttpRequest) {//IE7+、Firefox、Chrome、Opera、Safari的代码 xmlhttp=新的XMLHttpRequest(); } 其他的 {//IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } xmlhttp.onreadystatechange=函数() { if(xmlhttp.readyState==4&&xmlhttp.status==200) { txt=“AuthorTitle”; x=xmlhttp.responseXML.documentElement.getElementsByTagName(“书”); 对于(i=0;i,javascript,iis,Javascript,Iis,这是因为。您不能使用ajax调用外部站点。如果您真的想使用,您必须使用。或者您可以为此使用服务器端代理。也就是说,在服务器端调用外部站点并对该Web服务进行ajax调用。 有关更多详细信息,请参见我对以下问题的回答, 该页面是否也在端口8081上提供?否。只有xml页面位于iis服务器中。并且.html保存在本地驱动器中。html和xml必须来自同一服务器(技术上相同的url域,可以是不同的机器)。在您的情况下,页面有一个文件url,而xml有一个localhost:8081 url,因此浏览器

这是因为。您不能使用ajax调用外部站点。如果您真的想使用,您必须使用。或者您可以为此使用服务器端代理。也就是说,在服务器端调用外部站点并对该Web服务进行ajax调用。 有关更多详细信息,请参见我对以下问题的回答,

该页面是否也在端口8081上提供?否。只有xml页面位于iis服务器中。并且.html保存在本地驱动器中。html和xml必须来自同一服务器(技术上相同的url域,可以是不同的机器)。在您的情况下,页面有一个文件url,而xml有一个localhost:8081 url,因此浏览器将不允许您使用xmlhttprequest,因为域不同。此外,xmlhttprequest无法使用文件url(除非修改高级浏览器设置,否则不能使用所有浏览器)我强烈建议您使用reed Chamika的答案,因为这是正确的答案。上述代码在IE中运行良好,但在Chrome和FF中不工作。是否存在任何浏览器故障。希望您能阅读我给出的答案。转到链接的答案,您将找到解决方案。没有浏览器问题。同源策略问题我没有正确使用web服务.?但建议您使用显示web服务内容的链接。此链接适合我的查询非HTTP同步请求吗?同源策略不基于同步或异步请求。我在上面链接中的一个建议是在服务器端加载sample.xml部分,并公开一个可以使用javascript访问的服务或页面方法。因此至少将位于同一个域中,您可以访问它而不会出现任何问题。
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(url)
{
var xmlhttp;
var txt,x,xx,i;
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>Author</th><th>Title</th></tr>";
x=xmlhttp.responseXML.documentElement.getElementsByTagName("book");
for (i=0;i<x.length;i++)
  {
  txt=txt + "<tr>";     
  xx=x[i].getElementsByTagName("author");
    {
    try
      {
      txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
      }
    catch (er)
      {
      txt=txt + "<td> </td>";
      }
    }
    xx=x[i].getElementsByTagName("title");
    {
    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://localhost:8081/sample.xml')">GetDetails</button>
</div>
</body>
</html>