簡體   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