Stuck trying to parse XML using AJAX and Javascript with XMLHttpRequest -
re-edit of innerhtml show how many div's included in finished code. re-edit of start function not work , i'm not sure @ point broke it.
var fname = name; function load() { var x = new xmlhttprequest(); x.open ("get", "file1.xml",true); x.onreadystatechange = handleserverinput; x.send(); xml =x.responsexml; fname = xml.getelementsbytagname("name")[0]; name = fname.childnodes[0].data; function handleserverinput() { if (x.readystate == 4 && x.status == 200) { function displaydiv() { var html = ""; html+= " <div id = \"displayouter\">"; html+= " <div id = \"displayinner\">"; html+= " <p id = \"fname\">"; html+= " </p>"; html+= " </div>"; html+= " <div id = \"displayinner2\">"; html+= " </div>"; html+= " <div id = \"displayinner3\">"; html+= " </div>"; html+= " </div>"; return html; } function start() { document.body.innerhtml+=displaydiv(); var displayouterdiv = document.getelementbyid("displayouter"); displayouterdiv.style.display= "block"; var innerdiv = document.getelementbyid('displayinner'); innerdiv.innerhtml = fname; } // alert ( this.responsetext ); } } } window.onload = load;
so put displaydiv function inside handleserverinput function , imput data html div when set false don't want. can explain me why is? here update of code.
var fname = name; function load() { var x = new xmlhttprequest(); x.open ("get", "file1.xml",false); x.onreadystatechange = handleserverinput; x.send(); function handleserverinput() { if (x.readystate == 4 && x.status == 200) { document.body.innerhtml+=displaydiv(); div = document.getelementbyid('displayinner'); div.innerhtml = fname; } function displaydiv() { var html = ""; html+= " <div id = \"displayinner\">"; html+= " <p id = \"fname\">"; html+= " </p>"; html+= " </div>"; return html; } } xml =x.responsexml; fname = xml.getelementsbytagname("name")[0]; name = fname.childnodes[0].data; }
try assigning fname
before use it. assume want use x.responsexml
on 200 response, should move
xml =x.responsexml; fname = xml.getelementsbytagname("name")[0]; name = fname.childnodes[0].data;
into if statement, somewhere before div.innerhtml = fname;
happens
Comments
Post a Comment