+ 3

Why is my xhr requests pending?

I'm catching requests with HTTPServer and BaseHTTPRequestHandler class Server(BaseHTTPRequestHandler): def do_GET(self): self.response(200, { "Content-type": "text/html", "Access-Control-Allow-Origin": "*" }) self.write("success") def write(self, text): self.wfile.write(bytes(text, "utf-8")) def response(self, code, headers): self.send_response(int(code)) for key in headers: self.send_header(key, headers[key]) self.end_headers() server = HTTPServer(("localhost", 3000), Server) server.serve_forever() When viewed from browser it works perfectly. But when sent with javascript it receives the requests but it doesn't send the response status which leaves the request hanging.

6th Jul 2018, 6:22 PM
Toni Isotalo
Toni Isotalo - avatar
10 Answers
+ 2
Okay so. The problem was that I had youtube open. Or if any other side is loading in a new tab. My internet shouldn't be that bad tho...
6th Jul 2018, 7:58 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
Nothing special about it var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { alert("success") } }; xhttp.open("GET", "http://localhost:3000", true); xhttp.send(); Sometimes it success but with a huge delay
6th Jul 2018, 7:33 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
Python version: 3.6 windows 10 google chrome and edge Last request delay 43 seconds.
6th Jul 2018, 7:48 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
Just for sure... Can you insert self.wfile.flush() at end of do_GET() ?
6th Jul 2018, 7:55 PM
KrOW
KrOW - avatar
0
You have start serving? server.serve_forever()
6th Jul 2018, 6:58 PM
KrOW
KrOW - avatar
0
I presume that you have started serving because you have edited the code... Anyway, can you post the xhr code?
6th Jul 2018, 7:17 PM
KrOW
KrOW - avatar
0
Strange... I have do some test and all worked normally... Browser: Firefox 47.0.1 (used for either web and xhr request) Python version: 3.6 on Windows 7 32b Which are your specs?
6th Jul 2018, 7:42 PM
KrOW
KrOW - avatar
0
đŸ˜€đŸ˜€đŸ˜€
6th Jul 2018, 7:59 PM
KrOW
KrOW - avatar
0
Hey but your connection is local, how you can get so mich delay? It dont depends on your internet connection
6th Jul 2018, 8:02 PM
KrOW
KrOW - avatar