I was trying to get data back from an ajax call, and was using the code
jQuery.ajax({
type: 'POST',
url: '/chatlog',
success: exoticlangAjaxCompleted,
data:'messageLog=' + privateMessageLogJson,
dataType: 'json'
});
The data was in a JSON array (key = “messageLog”)
Why did it work to call
success: exoticlangAjaxCompleted,
but not
success: exoticlangAjaxCompleted(),
or
success: exoticlangAjaxCompleted(messageLog) ??
JS function is:
function exoticlangAjaxCompleted(messageLog){
console.log('exoticlangAjaxCompleted!');
console.log('chat log is: ' + messageLog);
console.log('chat log is: ' + dump(messageLog));
}
The
successargument expects a reference to function that will be invoked when the AJAX request is complete.With the following:
You are passing a reference to a function as required.
Whereas in this instance:
You are invoking your
exoticlangAjaxCompletedfunction and passing the result to thesuccessargument. Unless your function returns a function, this will not work!