On alert it always alerts jojo. The test2.php have text Loco
The div gets updated to Loco but the global variable is not changing. I tried window.temp = data but it didn't worked.
How can i get the returned value in variable? please Guide...
<div>
yolo
</div>
<script type="text/javascript">
var temp = 'jojo';
$.ajax({
url: 'test2.php', //Loco
success: function(data)
{
temp = data;
$('div').html(data);
},
error: function (err)
{
alert('error');
}
});
alert(temp);
var toBeUsedLater = temp; //updated temp value from ajax call
refreshTab();
</script>
async: falseoption for my current situation.async: falsemakes the ajax synchronous but it is not used in most cases becuase it pauses the execution until the ajax returns and the page might freeze. So better place to put the staementvar toBeUsedLater = temp;is either insuccesscallback(where you are setting innerhtml) or in some promise hook. You may read about jquery promises.