Reputation: 315
How would I go about writing a function that takes a function as a parameter and runs the callback function with an array pulled from the server as its parameter. So if I ran something like:
getArray(display)
getArray
would retrieve an array from the server, then display would write that array into the html.
Upvotes: 0
Views: 42
Reputation: 104775
Like so:
function getArray(callback) {
$.ajax({
..//options
success: function(data) {
callback(data);
}
});
}
function display(array) {
console.log(array);
}
//call it!
getArray(display);
Upvotes: 1