jquery - How to use response data from ajax success function out of Ajax call -


i have question, when make ajax call, , in success function json data, can't use out of success function

 $.ajax({         type: 'get',         url: url,         datatype: 'json',         success: function (response) {             getdata[name] = response;          }     });  alert(getdata[name]); 

my question how work getdata out of ajax call

the problem default ajax request async
means ajax start request execute: alert(getdata[name]); finish request in background , call success function.

so alert execute before success function. , want have tell ajax not execute thing before done, in other ward set async: false
second thing have declare variable outside ajax scope can access outside ajax

the final code :

var getdata; $.ajax({         type: 'get',         url: url,         datatype: 'json',         async: false,         success: function (response) {             getdata[name] = response;          }     });  alert(getdata[name]); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -