I need to use in some function the value of variable, which is generated inside internal function of ajax success. Contrary to the rules, the new value is not available outside of ajax function. However if I add alert after the internal function - variable becomes available! Here is clear example of what I mean. In this case alert will show nothing and variable is not available for the subsequent javascript:
$(document).ready(function() {
function somename() {
var exRate = 0;
$.ajax({
type: 'POST',
url: 'checkrate.php',
data: 'pic_url=' + picurl,
success: function(data){
exRate = data;
} // end ajax success function
}); // end ajax
alert(exRate);
}
});
BUT in this case (code is the same, just two alerts) - second alert already shows correct value of the new variable:
$(document).ready(function() {
function somename() {
var exRate = 0;
$.ajax({
type: 'POST',
url: 'checkrate.php',
data: 'pic_url=' + picurl,
success: function(data){
exRate = data;
} // end ajax success function
}); // end ajax
alert(exRate);
alert(exRate);
}
});
Please help!