admin管理员组文章数量:1426804
My code is:
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "results.xml", false);
xhttp.send();
myFunction(xhttp);//(this);
}
function myFunction(xml)
{
var xmlDoc = xml.responseXML;
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xml.responseText, "application/xml");
var x;
var txt = "";
var y;
y = xmlDoc.getElementsByTagName("entryresult");//.childNodes[0];
x = y[1].getElementsByTagName("title")[0].childNodes[0].nodeValue;
alert(x);
}
I am using cakephp. My custom.js is located in webroot/js. My xml file results.xml is located at the same folder.
But always got the message:
- GET XHR http://localhost/cakephp-3-4-3/result/results.xml [HTTP/1.1 404 Not Found 422ms]
- XML Parsing Error: mismatched tag.Expected: .
- TypeError: y[1] is undefined[Learn More]
Those errors are from the console (F12).
My code just do that because i cannot go further than the line before the alert.
i think i am trying to read a file from other folder.
My code is:
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "results.xml", false);
xhttp.send();
myFunction(xhttp);//(this);
}
function myFunction(xml)
{
var xmlDoc = xml.responseXML;
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xml.responseText, "application/xml");
var x;
var txt = "";
var y;
y = xmlDoc.getElementsByTagName("entryresult");//.childNodes[0];
x = y[1].getElementsByTagName("title")[0].childNodes[0].nodeValue;
alert(x);
}
I am using cakephp. My custom.js is located in webroot/js. My xml file results.xml is located at the same folder.
But always got the message:
- GET XHR http://localhost/cakephp-3-4-3/result/results.xml [HTTP/1.1 404 Not Found 422ms]
- XML Parsing Error: mismatched tag.Expected: .
- TypeError: y[1] is undefined[Learn More]
Those errors are from the console (F12).
My code just do that because i cannot go further than the line before the alert.
i think i am trying to read a file from other folder.
Share Improve this question asked Jun 28, 2017 at 21:44 Sandra G.Sandra G. 1291 gold badge4 silver badges17 bronze badges 2-
1
Your first issue is you are getting a 404 error, it cannot find your results.xml file.
GET XHR http://localhost/cakephp-3-4-3/result/results.xml [HTTP/1.1 404 Not Found 422ms]
This means either the results.xml file is not publicly accessible, or it is looking in the wrong location for it (/cakephp-3-4-3/result/results.xml
) – AlienHoboken Commented Jun 28, 2017 at 21:51 - Changed: xhttp.open("GET", "results.xml", false); to: xhttp.open("GET", "../webroot/files/p1/results.xml", false); Now it continued with the following steps. – Sandra G. Commented Jun 28, 2017 at 22:31
1 Answer
Reset to default 2My problem was solved by changing the line: xhttp.open("GET", "results.xml", false);
to: xhttp.open("GET", "../webroot/files/p1/results.xml", false);
本文标签: using javascript to open xml fileStack Overflow
版权声明:本文标题:using javascript to open xml file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745407112a2657300.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论