I have a function that uses AJAX to return data from a database. The data is processed and returned in JSON and, from there, I make the necessary manipulations. So:
function getData() {
$.ajax({
url: 'script.php',
type: 'post',
statusCode: {
200: function(res) {
res.forEach(function(data){
// do something
})
}
}
})
}
What I want to know is how to execute another function that handles this data returned in JSON by calling this function, like we do when we capture a click:
$('seletor').on('click', function(){
// do something...
})
And with my function, it would be something like this (I'm not even sure if this is correct):
getData(function(){
// do something with JSON data...
})
I do not know how to declare this function and "make it available" to be manipulated with another function.
I use state codes in HTTP headers to perform different functions in different scenarios. There is only 200 success code, and it is where I want to manipulate the JSON object returned by the AJAX request.
How to do this?