How to return data from success
response?
Here is my code:
$.ajax({
async: 'true',
url: 'https://exampleapi.com/product',
type: 'GET',
data: {page: idQuery},
success:(response => {
var idQuery = response.number;
})
})
the goal is to put the variable in response (idQuery)
to the data and it will become query param
.
Should I using callback in success response? or any idea?
Thanks for help
3
Answers
That’s correct that you would have to nest the callbacks if you wanted to do it that way. However, my understanding is that
jqXHR
will return a Promise-like object, which allows us to chain things together as such:Callback is an option, another option is setting the async flag
false
you can create a custom function that use the response as an input param
i hope it works for you.