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
Post a Comment