How to display Ajax data

I have the following code to get the content of multiple DIV’s. Im using AJAX.
I know that responseText would give me the result…but how do I break this response up in different chunks so I can assign it to the individual divs?

if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            
            document.getElementById("div1").innerHTML = responseText;
            document.getElementById("div2").innerHTML = response?????;
            document.getElementById("div3").innerHTML = response?????;
        }
    };
    xmlhttp.open("GET","getstatistics.php",true);
    xmlhttp.send();

well, what defines the boundary of ‘a chunk’?

I mean just content…statistic…numbers…etc…per DIV container

var myObj = JSON.parse(this.responseText);
document.getElementById(“demo”).innerHTML = myObj.name;

Will that work?

Assuming your response is a JSON object with a value called ‘name’ in it, that would work.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.