samedi 30 juillet 2016

How to use a global variable with jquery?

I have a code as shown below.

    var globalVar = ''
    $.get("some.php", function(data, status)
    {
        alert(data)
        globalVar = data
    });
    alert(globalVar)

While the first alert shows the value of data, the second alert doesn't. It seems like globalVar was not properly assigned inside the get's function. What would be the proper way to use a global variable here?




Aucun commentaire:

Enregistrer un commentaire