[Answered ]-My api call doesnot work in javascript but works fine with in postman and browser

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;

Leave a comment