Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get file from another server?
    primarykey
    data
    text
    <p>I am learning how to perform XHR and placed the code from w3school in my webserver(tomcat7) to try it out. When I placed "note.xml" in the same file as the html, I can use the code below to get the XML file.</p> <pre><code>xmlhttp.open("GET","note.xml",true); </code></pre> <p>However, if I move "note.xml" to another webapp location, I can't use the same method. Neither does the code below is able to get the XML file.</p> <pre><code>xmlhttp.open("GET","http://localhost:8080/anotherWEBapp/note.xml",true); </code></pre> <p>HTML:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;h1&gt;W3Schools Internal Note&lt;/h1&gt; &lt;div&gt; &lt;b&gt;To:&lt;/b&gt; &lt;span id="to"&gt;&lt;/span&gt;&lt;br /&gt; &lt;b&gt;From:&lt;/b&gt; &lt;span id="from"&gt;&lt;/span&gt;&lt;br /&gt; &lt;b&gt;Message:&lt;/b&gt; &lt;span id="message"&gt;&lt;/span&gt; &lt;/div&gt; &lt;script&gt; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","http://localhost:8080/test-app/note.xml",true); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.getElementById("to").innerHTML= xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue; document.getElementById("from").innerHTML= xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue; document.getElementById("message").innerHTML= xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue; &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Is there anyway I am able to get the XML file with the use of javascript only?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload