I'm 开发者_运维知识库currently working on a project trying to update a page reading from an XML file on our intranet server. After doing some working I came up with the following code:
// 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;
}
Now I've tested this code on my localhost and it does in fact read from the correct file, displaying the updated information, but when I deploy it to the intranet, I get an "Invalid Argument" error. (The XML file itself has been deployed and is referencing correctly).
Edit: I've recently found the problem, in that the path I was referencing apparently couldn't find the file itself. So that brings up another question that someone might be able to shed light on:
//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);
Perhaps someone could shed some light on this?
should your path be something like this:
xmlhttp.open("GET","./Path/Here/books.xml", false); //for relative urls
xmlhttp.open("GET","http://localhost/Path/Here/books.xml", false); //for absolute urls
and if its a non-http synchronous request
var request = new XMLHttpRequest();
request.open('GET', 'file:///home/user/file.json', false);
its not similar to your system path.
The path here is wrong:
xmlhttp.open("GET", "\\\\Full\\Server\\Path\\Here\\Sample.xml", false);
You are using the wrong type of slashes for the internet, they would be correct on a file system. It needs to use a forward slash.
xmlhttp.open("GET", "//Full/Server/Path/Here/Sample.xml", false);
Have you checked the same-origin policy?
精彩评论