0

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.

1 Answer 1

1

Like so:

function getArray(callback) {
    $.ajax({
        ..//options
        success: function(data) {
            callback(data); 
        }
    });
}

function display(array) {
    console.log(array);
}

//call it!
getArray(display);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.