I am using XAMPP Apache on port 80.
When I try with localhost
in the url
I get:
XMLHttpRequest cannot load http://localhost/ice_escape/pokus.xml. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
and also:
Uncaught TypeError: Cannot read property '0' of null
I tried allowing CORS by adding this to httpd.conf to no avail:
Header always set Access-Control-Allow-Origin "*" Header always set Access-Control-Max-Age "1000" Header always set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding" Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Then I tried changing localhost
to 127.0.0.1
. It removes the first error, but the other error persists.
var url = "http://127.0.0.1/iceescape/pokus.xml"; var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } if (xmlhttp) { xmlhttp.open("GET", url, true); xmlhttp.setRequestHeader('Content-Type', 'text/xml'); xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4) { txt = xmlhttp.responseText; {//---- some code that parses the xml var strWidth = "width"; var a = txt.indexOf(strWidth); a += strWidth.length; txt = txt.slice(a,(txt.length) ); var width = txt.match(/\d+/)[0];// here it says its null } } } }; xmlhttp.send();
the xml:
<?xml version="1.0" encoding="UTF-8"?> <map width = "2400" height = "1800"> <ghost type="troll" speed="5"> <point> {100,200} </point> <point> {350,250} </point> </ghost>
No comments:
Post a Comment