jquery - Global variable in javascript doesn't changed -



jquery - Global variable in javascript doesn't changed -

$check = ""; $.ajax({ url: "check.php", type: "post", cache: false, data: $name + "=" + $value, success: function(data){ $check = data; alert($check); } }); alert($check);

the first msg "hello"

the sec msg "" why ?

$.ajax asynchronous function, returns , calls success callback when success response received.

therefore, when alert($check) @ bottom of code executed, value of $check not yet modified callback of ajax. that's why see empty string.

javascript jquery variables global-variables

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -