xml - responseXML is null, javascript -


presentation.htm:

if(!system.ie) {     try {         descxmldocument = new xmlhttprequest();         descxmldocument.async = false;         descxmldocument.onreadystatechange=checkdescxmlload;         descxmldocument.open("get", "description.xml", true);         descxmldocument.send(null);     } } 

tacore.js:

if (descxmldocument.readystate == 4 && descxmldocument.status == 200) {     alert("error"); } else {     document.getelementbyid('progresscount').innerhtml="��������o";     document.getelementbyid('progressdiv').style.display="none";     anodes=descxmldocument.responsexml.documentelement.childnodes;     document.getelementbyid('zback').innerhtml = anodes[0].text;     document.getelementbyid('coursepicture').innerhtml = anodes[1].text;     document.getelementbyid('chaptername').innerhtml = anodes[2].text;     document.getelementbyid('buttonsdiv').innerhtml = anodes[3].text;     document.getelementbyid('generaldescription').innerhtml = anodes[4].text;     document.getelementbyid('generalhelp').innerhtml = anodes[5].text;     document.title=document.getelementbyid('chaptername').innertext; } 

i following error:

descxmldocument.responsexml null

does know how fix it?

your 'checkdescxmlload' backwards. xml have arrived when readystate === 4 , status === 200, not other way around. written, try reading xml on readystate 1,2 , 3 well, when hasn't arrived yet. switch around if else , move error alert elsewhere.

checkdescxmlload = function() {     if (descxmldocument.readystate === 4) {         if (descxmldocument.status === 200) {             ...... /* response handler */             anodes = descxmldocument.responsexml.documentelement.childnodes;             ...... /* response handler */         }         else {             alert('error');         }     } } 

as anik says, xml ready read once reach state 4 , status 200.

if want things on readystate 0,1,2 , 3 well, can indeed use 'switch case'. if dont want other readystates, can use descxmldocument.onload() instead of descxmldocument.onreadystatechange, work in (almost?) modern browsers.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -