The function addToPlaylist
doesn't return
anything. It makes an asynchronous request, which eventually executes a callback function, which returns something. The original addToPlaylist
function is long done and returned by the time this happens though, and the callback function returns to nobody.
I.e. the success: function(msg) { }
code executes in a different context and at a later time than the surrounding addToPlaylist
function.
Try this to see it in action:
function addToPlaylist() {
$.ajax({
...
success : function () {
alert('second'); // comes after 'first'
return null; // returns to nobody in particular
}
});
alert('first'); // comes before 'second'
return 'something'; // can only return here to caller
}