繁体   English   中英

Javascript XMLHttpRequest无效参数

[英]Javascript XMLHttpRequest Invalid Argument

我目前正在一个项目中,尝试更新我们Intranet服务器上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);  

您在互联网上使用了错误的斜杠类型,它们在文件系统上是正确的。 它需要使用正斜杠。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM