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.

Java is not Java Script. Moving to correct forum...

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.

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

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.

Thanks!)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.