1π
I believe your problem is with the xhttp.open
code. When you ask to perform the βGET,β setting the boolean at the end to true will mean the request will perform asynchronously. You should set this variable to false
, which means the method does not return until the response is received.
Try changing
xhttp.open("GET","192.168.0.101:8000/students/",true);
to:
xhttp.open("GET","192.168.0.101:8000/students/",false);
Here are good sources:
Hope it helps!
EDIT
Since it seems you are the owner of the server, you can try manually implementing a CORS header on your server, or use JSONP (which bypasses CORS). Hereβs some info on CORS and implementing on MDN. There also this nice source on SO. Good luck!
π€cosinepenguin
1π
When you make the request
the content of response will be parsed automatically.
Change
var1 response = JSON.parse(xhttp.responseText);
To
var1 response = xhttp.responseText;
Source:stackexchange.com