0

Hi everyone,
can anyone explain me why following code alerts me nothing:

var text = $.ajax({
  type: "POST",
  url: "registration.php",
  data: "email=" + elementValue
}).responseText;

alert(text);

but when I add option "async: false":

var text = $.ajax({
  type: "POST",
  async: false,
  url: "registration.php",
  data: "email=" + elementValue
}).responseText;

alert(text);

everything goes ok. Why is that? what does asynchronous actually mean?

P.S.: server code registration.php is ok.

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Acute
0

Asynchronous means it runs without waiting for an answer. So in the 1st situation, while registration.php is running, text has no result yet and thus displays nothing. The second code, where async is false, runs until the php file is done, before displaying the value of text.

0

Thank you pritaeas,
so when do we use asynchronous then???(for example)

0

Suppose I want to display a third party RSS feed on my website. Then I want to retrieve it, but not wait until it is completed. Suppose the server is down. I'd still want to finish loading my page independently.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.