Languages

Menu
Sites
Language
XMLHttpRequest
var client = new XMLHttpRequest(); client.onreadystatechange = function() { if (client.readyState == 4 && client.status == 200) { callback(client.responseText); /* * alert(client.status + "Response " + client.responseText); */ } } is XMLHttpReques.tonreadystatechange runs on different thread? coz its not waiting for response it executing other stuff also i want it should wait for response then do other stuff

Responses

3 Replies
AVSukhov

Hello,

About sync and async request you can find in doc:

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requests

Vikram

Hi,

No, I think it's executing in the same thread. 

"client.onreadystatechange = ... " is just to register a callback function on the XMLHttpRequest instance "client", it will be get called while you start the http request such as client.open(url). You shouldn't to block the subsequential scripts executing, also this is the right process. You should add those scripts (which depend on the response) in the callback.

Marco Buettner

You should learn the basics :)