HTTP GET Request, Response

152 Views Asked by At

I have a file where I send GET request to another file, and I got the response show up under Network tab of Google Dev Tools, but it did not display on my browser.

This is what I do for passing the response to display in my browser.

 xmlhttp.onreadystatechange = function() {
            if(this.readyState == 4){
                
                res = xmlhttp.responseText;
                
                document.getElementById('table3').innerHTML = res;
            }
        }

And I want to display the response under the table of id = "table3" like below.

<td id="table3"> 
<td>

The content inside was passing from the response of GET request.

Any help is appreciated. Thank you

1

There are 1 best solutions below

2
Sheel Pant On

I think that your if statement in the onreadystatechange callback is wrong. xmlhttp is the instance of the XHR class, which would mean that instead of using this, you would have to use xmlhttp, and not this. this in the context of your program likely is the window object.