Possible Duplicate:
Jquery: Return the value of a ajax call to caller function?
In the code below ,
I'm trying to put my ajax call in a function that needs it but makeIt() wont return "usa from the ajax call ? Or am I going about this all wrong?
var makeIt = function () {
var getStuff = function () {
return $.ajax({
type: "POST",
url: "my.php",
data: {
id: "2"
},
success: function (data) {
data
}, // data will return string "usa"
error: function () {
alert("error");
}
});
};
return getStuff();
};
var result = makeIt() //result should = "usa"