1

I am new to html and javascript and need some help.

So i have a html page that has a button on it. and when i click that button i want it to load the xml document ( and eventually display some sort of information from it). I don't know that I am not loading the file correctly. If i comment out the xhttp.send; it will run through. So the line the xttp.send is on is where i am having my problems.

Notes to consider: I am writing in notepad++, the .xml file is in the same directory as my .html file, I am using chrome as a browser.

Thanks in advance

var xhttp;
function functionName(){
    xhttp=new XMLHttpRequest();


    xhttp.open("GET","test.xml", false);
    xhttp.send();
    //xmlDoc=xmlhttp.responseXML; 
    //var temp =  xmlDoc.getElementsByTagName("alerts");
    alert("something");

 }

</script>
vivekpansara
  • 895
  • 1
  • 6
  • 14
  • This should help: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest – Felix Kling Feb 24 '14 at 02:30
  • 1
    @MattBall - note that the question you've linked uses asynchronous request while this one tries synchronous one. While async is generally better I'm not sure if dup is the right one... (using jQuery.ajax may be even easier but again not what asked in the question) – Alexei Levenkov Feb 24 '14 at 02:31
  • 5
    If you are loading the page from the local file system, Chrome won't let you make Ajax requests to local files, unless you start it with a flag (I think). See http://stackoverflow.com/q/16585514/218196 – Felix Kling Feb 24 '14 at 02:31
  • @AlexeiLevenkov indeed! – Matt Ball Feb 24 '14 at 02:32
  • so, what's happening? are you sure the function is getting called? what does the html look like? – thescientist Feb 24 '14 at 02:56

1 Answers1

0

You will have to give the full http path to your xml resource.

Ren
  • 437
  • 4
  • 17