0

I want to dynamically change page content based on XML Ajax response. For testing I have created a static PHP generated XML file with only one tag. If the tag contains the string "yes" then it should display "AVAIL" otherwise display something else. The static value set for testing is "yes" but the script still displays "Not Avail".

What is the correct way to accomplish this?

I have some AJAX here..

xmlhttpp.onreadystatechange=function(){
if(xmlhttpp.readyState==4 && xmlhttpp.status==200){
    var response = xmlhttpp.responseXML;
    var avail = response.getElementsByTagName("avail")[0];
    if(avail.childNodes[0].nodeValue == "yes"){
        document.getElementById("dstat").innerHTML = "AVAIL";
    }else{
        document.getElementById("dstat").innerHTML = "NOT AVAIL '" + avail + "'";
    }


}

}

And the domain_checker.php file looks like this..

<?php
Header('Content-type: text/xml');
echo "<?xml version='1.0' encoding='UTF-8'?>
<domain>
  <avail>yes</avail>
</domain>";
?>
1
  • Is your php returning the proper result? Commented Jul 7, 2013 at 23:55

1 Answer 1

2

avail is an xml node, what you want is the text inside the node to test against

    avail = response.getElementsByTagName("avail")[0];
    if(avail.childNodes[0].nodeValue == "yes"){
        document.getElementById("dstat").innerHTML = "AVAIL";
    }else{
        document.getElementById("dstat").innerHTML = "NOT AVAIL";
    }
Sign up to request clarification or add additional context in comments.

2 Comments

This didn't work for me. Now my code doesn't do anything at all, it's broken somehow. I updated the javascript portion of my question.
My client has not yet decided upon hosting so for the time being I'm using 000webhost for live development. That host automatically include javascript on all pages which was breaking my XML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.