Trying my hand a Javascript, I came across an issue with XMLHttpRequest. This is probably something I'm doing wrong, so any help would be appreciated.

reader = new XMLHttpRequest()"GET","Votes.xml")

when I run this, it alerts that the readyState is 1 (Send has not been called) and then stops. If I comment out the "reader.send()" then it continue with the second alert (And all the code that follows). Am I missing something simple?

Recommended Answers

All 5 Replies

I'm not quite sure just what you're trying to do, but I've used XMLHttpRequest and so maybe this will help.

var reader = new XMLHttpRequest();"GET", hostpath + "Votes.xml", true);
reader.onreadystatechange = function ()
    if (reader.readyState == 4)
        if (reader.status == 200)
            var votes = reader.responseText;

You would then get the contents of the file into a variable and it should alert the readyState.
Hope this helps...

That helped a little. Using the onreadystatechange the readystate is now 4, but the status remains 0 and the variable doesn't get any of the files contents.

causes the program to stop, but just useing "Votes.xml" runs fine.

Oh, I don't know why I included hostpath... My bad.
Ummm, I'm not quite sure what might've happened, but perhaps Votes.xml is empty?


    <Name>Voter 1</Name>  <Vote>5</Vote>

Thought I'd start with a small file and try to read a single vote.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.