jquery to php (wait for php script until result/finish)

Posted by user354051 on Stack Overflow See other posts from Stack Overflow or by user354051
Published on 2010-06-02T16:33:45Z Indexed on 2010/06/02 17:23 UTC
Read the original article Hit count: 249

Filed under:
|

Hi,

I am executing a php call from javascript(jQuery), php sript is sending result back. The problem is that these php scripts are taking some time (milliseconds), and java script is not waiting for them to finish, thus variables are not getting initialized with correct values. The code is simple:

$.get("php/validation.php",{'email':email},function(data){
// valid_email now contains true/false
alert(data);
if(data=="true"){
var valid_email = true;}
}); 

The "alert" is printing true but value of valid_mail is recognized as "false" in the code below. Is there any other better way to call php scripts and wait for until they are not finished?

Prashant

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery