Recently I deployed Python on my IIS server, and started testing some requests. First I created the javascript code, as you can see below:
sendRequest = function() {
var http = new XMLHttpRequest();
http.onreadystatechange = function() {
if (this.readyState = 4 && this.status == 200) {
console.log("ok!");
var response = this.responseText;
console.log(response);
}
};
http.open("GET", "test.py", true);
http.send();
console.log("called");
}
The test.py file has the following code:
print('Content-Type: text/plain')
print('')
print('Hello!')
print('Hi')
However, the output I get on the console is:
ok!
(nothing)
ok!
Hello!
Hi
ok!
Hello!
Hi
As far as I tested, the sendRequest function is only executed once, and I have found that the onReadyStateChange
function is executed three times, why?
Can anyone tell me why this happens? Any help is appreciated.