That code is confusing, as it returns a value that is never used.
That last line should look like this:
fn(messages);
Returning anything from the callback to the done
method is pointless, as it will just be ignored.
The value for the parameter fn
when you call the function should be a function, which will be called when the AJAX call is complete. That is the way that you pick up the result from the AJAX call.
Example; assume that the function is named xyz, you call it like:
xyz(function(msg) {
// in here you can use the `msg` parameter to get the messages from the call
alert(msg);
});