This question already has an answer here:
How would I, using $.post() in a function, force the return on the post callback?
Example:
function myFunction(){
$.post(postURL,mydata,function(data){
return data;
});
}
I have tried playing around with it using .done() and .queue() however neither has worked for me. I understand there is a fundamental flaw in my example; with that said, how can I achieve my desired functionality?
This is impossible. $.Ajax calls will always return immediately. You need to deal with the return when it is called through a callback (possibly several seconds later). Javascript never blocks for a given call. It may help to think of your code like this:
If you're interested more on the benefits (and drawbacks) of Javascript's no-blocking, only callbacks: this Node.js presentation discusses its merits in excruciating detail.