Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.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 XMLHttpRequest参数无效_Javascript_Xmlhttprequest - Fatal编程技术网

Javascript XMLHttpRequest参数无效

Javascript XMLHttpRequest参数无效,javascript,xmlhttprequest,Javascript,Xmlhttprequest,我目前正在做一个项目,试图更新一个从内联网服务器上的XML文件读取的页面。在做了一些工作之后,我想到了以下代码: // IE7+ if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } // IE6, IE5 else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET", "VerifiedUrl+XML.xml", false);

我目前正在做一个项目,试图更新一个从内联网服务器上的XML文件读取的页面。在做了一些工作之后,我想到了以下代码:

// IE7+
if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); }
// IE6, IE5
else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.open("GET", "VerifiedUrl+XML.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
if (xmlDoc.getElementsByTagName("CheckBox")[0].childNodes[0].nodeValue == "True"){
    document.getElementById("PartToUpdate").innerHTML = xmlDoc.getElementsByTagName("TextBox")[0].childNodes[0].nodeValue;
}
现在,我已经在本地主机上测试了这段代码,它确实从正确的文件中读取了更新的信息,但是当我将其部署到intranet时,我得到了一个“无效参数”错误。(XML文件本身已部署并且正在正确引用)

编辑:我最近发现了问题,因为我引用的路径显然找不到文件本身。这就引出了另一个问题,也许有人可以解释:

//When referencing a file within the same folder, it works correctly.  
xmlhttp.open("GET", "Sample.xml", false);

//However, if I include the full path, it doesn't read correctly.  (Double slashes to escape correctly)
xmlhttp.open("GET", "\\\\Full\\Server\\Path\\Here\\Sample.xml", false);  

也许有人能解释一下

您检查了吗?

您的路径应该是这样的:

xmlhttp.open("GET","./Path/Here/books.xml", false);  //for relative urls

xmlhttp.open("GET","http://localhost/Path/Here/books.xml", false); //for absolute urls
如果是非http同步请求

var request = new XMLHttpRequest();

request.open('GET', 'file:///home/user/file.json', false);

它与您的系统路径不同。

此处的路径错误:

 xmlhttp.open("GET", "\\\\Full\\Server\\Path\\Here\\Sample.xml", false);  
您在internet上使用了错误类型的斜杠,它们在文件系统上是正确的。它需要使用正斜杠

xmlhttp.open("GET", "//Full/Server/Path/Here/Sample.xml", false);  

结果发现两者都是同一起源的一部分。我找到了一个解决方法,但出于教育目的,我决定更新这个问题。