0

This the data im getting from post is a simple object and the return value is always empty. Its logging to the console fine. any ideas?

function getTaskData(item){
    var returnText = '';
    $.post("index.php", {name: "getTaskData", pk: item.taskDataId}, function(data){
        console.log(data);///Object {taskData: "Also - whats up with this?"}
        console.log(data.taskData);///Also - whats up with this? 
        returnText = data.taskData;
},"json");
    return returnText;
}
mike_l
  • 108
  • 6

1 Answers1

1

The code included in the block function(data) { ... is called a callback. It will be aynchronously called when the server's ajax call has finished. Whereas the return returnText will be called immediately.

Whatever you are going to do with the returntext (update DOM etc) will need to be done in the callback function

Scary Wombat
  • 44,617
  • 6
  • 35
  • 64