javascript - How do I insert the xml file data into a variable? -


i quite new javascript , xml. trying load external xml file can changed event handler (onclick). xml file loads ok. problem cannot retrieve xml data. variable xmldoc appears null. doing wrong?

also can recommend online courses javascript, xml , php education? need trained , well.

thanks code below:


external js file:

var xmlhttp; function getxmlhttpobject() { if(window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari return new xmlhttprequest(); } if (window.activexobject) { // code ie6, ie5 return new activexobject("microsoft.xmlhttp"); } return null; }   function loadxmldoc(url) { xmlhttp=getxmlhttpobject(); if (xmlhttp==null) { alert ("your browser not support xmlhttp!"); return; }  xmlhttp.open("get",url,true); alert (url); xmlhttp.send(); xmldoc=xmlhttp.responsexml; }  function get_set_data () {     var title=xmldoc.getelementsbytagname("title")[0].childnodes[0].nodevalue; document.getelementbyid("header").getelementsbytagname('h1')[0].innerhtml= title;  } 

html part: (page needs load default xml file)

<body onload="loadxmldoc('papers.xml'); get_set_data();">   <button onclick="loadxmldoc('papers.xml')">paper 1</button> <button onclick="loadxmldoc('paper2.xml')">paper 2</button>   <div id="header">     <h1> sample title </h1>     <h6> </h6> </div> 


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -