AJAX http request not returning when readyState is 4 = DONE, returns at 3 - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Tuesday, October 4, 2022

AJAX http request not returning when readyState is 4 = DONE, returns at 3

I have javascript client code making this http request call (including only the relevant code section):

...
var data = new FormData();
data.append('prog', x);
data.append('userid', <?php echo $id; ?>);
data.append('usecache', usecache);

var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'solveIt2.php', true);
xmlhttp.onreadystatechange = function() {
    document.getElementById("solve_button").textContent = "Solve";
    if (this.readyState == 4 && this.status == 200) {
        document.getElementById("yy").innerHTML = this.responseText;                     
    } else {
        document.getElementById("yy").innerHTML = "ERR1 (" + this.readyState + ", " + this.status + ") <> (4, 200)";
    }
};
xmlhttp.send(data);   

The server side solveIt2.php code is simply:

<?php
echo "blabla";
return;
?>

When looking at my html page I'm getting this: ERR1 (3, 200) <> (4, 200)

According to Javascript documentation XMLHttpRequest.readyState 3 means ==> LOADING Downloading; responseText holds partial data.

Why don't I get the http repose generated by the server? Do I need to write my client code differently and wait for state done only? how?



source https://stackoverflow.com/questions/73939769/ajax-http-request-not-returning-when-readystate-is-4-done-returns-at-3

No comments:

Post a Comment