Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript - XMLHttpRequest, result are always undefined
    primarykey
    data
    text
    <p>I'm trying to test if the xml file have the tag "<code>&lt;group&gt;</code>"</p> <pre><code>var xmlhttp = new window.XMLHttpRequest(); xmlhttp.open("GET", "xmlfile.xml", false); xmlhttp.send(null); xml = xmlhttp.responseXML.documentElement; var thegroup = xml.getElementsByTagName('group')[0]; if (!group) { alert('No &lt;group&gt; in the XML: ' + xml); return; } else { alert(xml + 'have a &lt;group&gt; tag'); } </code></pre> <p>Even if my xml file have the tag "<code>&lt;group&gt;</code>" the result is always negative, and the variable "<code>thegroup</code>" is undefined.</p> <p>"<code>xml</code>" give me "[object Element]"</p> <p>Where is my mistake?</p> <p>PS: I'm only interested in webkit, I don't care about IE, Opera or Firefox for now.</p> <p>EDIT : HERE IS MY ACTUAL CODE</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="CONTENT-TYPE" content="text/html; charset=UTF-8"&gt; &lt;title&gt;xmltest&lt;/title&gt; &lt;script type="text/javascript"&gt; function init() { var xmlhttp = new window.XMLHttpRequest(); xmlhttp.open("GET", "xmlfile.xml"); xmlhttp.send(null); xmlhttp.onreadystatechange = callbackFunction; function callbackFunction(){ if (xmlhttp.readyState == 4){ xml = xmlhttp.responseXML.documentElement; var group = xml.getElementsByTagName('group')[0]; console.debug(xml) if (!group) { alert('No &lt;group&gt; in the XML: ' + xml); return; } else { alert(xml + 'have a &lt;group&gt; tag'); } } } }; &lt;/script&gt; &lt;/head&gt; &lt;body onLoad="init();"&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and my xmlfile.xml :</p> <pre><code>&lt;?xml version="1.0" ?&gt; &lt;group type="vertical"&gt; &lt;name&gt;name&lt;/name&gt; &lt;title&gt;title&lt;/title&gt; &lt;/group&gt; </code></pre> <p>At this point the alert is triggered saying : No <code>&lt;group&gt;</code> in the XML: [object Element]</p> <p>So maybe my problem is just on the way I try to find the <code>&lt;group&gt;</code> tag ?</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.
 

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