jquery - variable returning undefined value in javascript -
i'm using function this
function example(){ var a; $.ajax({ url:"www.example.com/function", type: 'post', success: function(result){ a=result; } }); alert(a); }
i need variable outside of ajax function
here i'm getting result undefined. how can value there. ?
you can wait ajax call return, specifying async: false
.
function example(){ var a; $.ajax({ url:"www.example.com/function", type: 'post', async: false, success: function(result){ a=result; } }); alert(a); }
Comments
Post a Comment