I am having some security problems and need some help..
a little backstory.. I had the script running fine on my computer. . transfered them to my laptop, and the script still found and parses the xml like it should. however, i zipped them and sent it back to myself and now all the values come back undefined. .
here is the script. .
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
var xmlDoc = loadXMLDoc("nhl_standings_xml.xml");
var x = xmlDoc.getElementsByTagName("nhlall");
fairly straight forward and simple.. but values of x[0].textContent is coming back undefined.. i have all files (html, js, and xml) in the same folder on my desktop. they worked perfectly fine before when they were just on my desktop.. but now that won't even work. :/ help please
alert(xhttp.readyState + "---" + xhttp.status); //its its anything other than '4---200' this will give you the key to the error
alert("the xml data is: " + xhttp.responseXML); //has it sent any XML data at all
alert("the response text is: " + xhttp.responseText); did it send any text back
Sometimes it is the case that that the responseXML will be empty, or undefined, but the information will be in the reponseText.
PS-- Sorry for the hasty response--I was looking at the content of your post rather than the title. Did you indeed get an xhttp.status code that indicated that access was denied?
hello, it is very smart to test it in this way, but i received no alerts in the script.
it is very strange indeed. and my brain is about to bleed from picking over it for two days. ;p
IE and opera(as well as chrome and i assume firefox) are all giving me security errors at the line i stated above (when i pull up dev tools debugger).. a quick search on google and i pull up that i am crossing domains, yet all my files are local and in the same directory. :?
would setting up apache and testing it help at all do you think? it was all working perfectly before i zipped them
the files are coming locally - is there something wrong with that? why did it work fine a few days ago on all browsers without touching code? is it possible the browsers updated since then? sorry for so many question.. so frustrated.. should i somehow process them through a local server instead? (i will try apache here in a bit -- see if anything works out)
interestingly, what i said beforehand isn't true. everything is working as it should in firefox, but not chrome, ie, or opera ..
the files are coming locally - is there something wrong with that?
AJAX requests (same as any classical submit) will not work locally, unless you install a server (like Apache or IIS) on your computer and run your files under that server.
AJAX requests (same as any classical submit) will not work locally, unless you install a server (like Apache or IIS) on your computer and run your files under that server.
You'll need a server to run PHP etc, but I have no trouble running AJAX requests under the file:/// protocol.
This routine displays its own source:
Well, yes. Some browsers accept request even when the status of the document is 0, not 200. But somehow it looks safer to test locally under an installed server.
Now, back to the main problem:
Originally Posted by shawnku
but values of x[0].textContent is coming back undefined
I bet you are using an old version of IE on your laptop. Either upgrade your IE, or better use alternatively the innerText IE property. Rough code:
Code:
var text
if(element.textContent){
text=element.textContent;
}
else if(element.innerText){
text=element.innerTextt;
}
just tried oth of them and interestingly it's giving me a readystate of 4, and a status of 200 on all browser's including ie. doesnt that mean it should be working loading and executing properly?
I don't really know what '.textContent' is--what are the values of your xhttp.responseText and xhttp.responseXML? That's the key. Your original problem was getting the data to begin with. That now apparently is solved.
Bookmarks