global variable is showing blank always in jquery -


i have created global variable in jquery. created function in making jquery call , setting response var global variable. when doing console.log global var, showing blank always. code did is

var currentname = ""; function getcurrentname() {     $.get(         url     ).success(function(response) {         response = json.parse(response);         currentname = response.name;     }); } getcurrentname(); console.log(currentname); 

so should use variable globally.

you should use async : false in ajax request


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -