Question: I have an ajax call that looks like this. My question is, with the callback function I can get the data out from myAjaxCall() to another function so I can work on the data. But is it possible to do multiple callbacks, so I can pass the data to two, three or four different functions that do all different things to the data?

Or do I have to do multiple ajax request for every function that I want to use?

```
function myAjaxCall() {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'myJSON.json', true);

    xhr.onload = function() {
        if(this.status === 200) {
            var data = JSON.parse(this.responseText);
            callback && callback(data);
        }
    };
    xhr.send();
}

```

Answer: 
You can just wrap the callbacks in another function and use that wrapper function instead:

```
function callback(data) {
    callbackOne(data);
    callbackTwo(data);
    callbackThree(data);
    . . . 
}

```

If you need broader use of `data` than this, you'd need to resolve a `Promise` or something similar to get the data into a broader scope.
Another way could be this:

```js
function myAjaxCall(callbacks) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'myJSON.json', true);

    xhr.onload = function() {
        if(this.status === 200) {
            var data = JSON.parse(this.responseText);
            callbacks && callbacks.forEach(function(callback) {
                callback(data);
            })
        }
    };
    xhr.send();
}

// Where callback1 and callback2 are both functions
myAjaxCall([callback1, callback2]);
```

Note that I've changed the way of using **myAjaxCall**.

Also, if you don't mind using ES6, this would be a great option:

```js
function myAjaxCall(...callbacks) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'myJSON.json', true);

    xhr.onload = function() {
        if(this.status === 200) {
            var data = JSON.parse(this.responseText);
            callbacks.length && callbacks.forEach(callback => callback(data));
        }
    };
    xhr.send();
}

// Where callback1 and callback2 are both functions
myAjaxCall(callback1, callback2);
```

Note that in both cases I'm passing the callbacks to the ajax function, so no matter where that function is placed, it will have the callbacks available (I'm talking about scope). It's just not a good practice to define a function that uses user defined variables outside it's own scope.