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