I have a basic jQuery function:
$(document).on('click', '#myElement', function(){
alert( getItemDescription('2') );
});
My function gets called, and runs the following as expected:
function getItemDescription(id){
$.post("item_description.php", {id:id},
function () {
// ...
})
.done(function (data) {
return data;
})
.fail(function () {
return 'error';
});
}
When I look at the network tab in the console window, the .post() is successfully retrieving the correct info from item_description.php -- However my original function -- The alert simply replies undefined -- I have looked at the return manual in JS and read numerous posts on S.O. -- return is supposed to be able to return a literal is it not? What am I not seeing with this simple script? How do I get the retrieved variable data from getItemDescription into the alert ?