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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -