0
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 do the proper 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 perform another function that handles this data returned in JSON when calling this function, like we do when capturing a click:
$('seletor').on('click', function(){
// do something...
})
And with my job, it would be something like this (I’m not even sure if this is correct):
getData(function(){
// do something with JSON data...
})
I don’t know how to declare this function and "make" this object to be manipulated with another function.
I use status codes in HTTP headers to perform different functions in different scenarios. There is only the code 200 of success, and it is where I intend to manipulate the JSON object returned by the request with AJAX.
How to do this?
It was bad, it was for another question, I posted wrong
– user60252
regardless of the code, you want to execute a function at the end of the ajax request?
– Will
In the request response, you are expecting an array?
– Gustavo Sampaio