I need to clear the following doubt. I want to make 2 ajax requests, the problem is that I make request 1 (I get data) and I need to pass that data to request 2. I have done the following:
- I create an ajax (jquery) and get the data
- Within this ajax I create the following to send the data obtained to the following address
ERROR Doing it this way, I get cors error. If I do the ajax from the outside I can't get the data from request 1
POSSIBLE SOLUTION When obtaining the data from request 1, save it in a hidden input and then take it and make the second request
NOTE I think there should be another more practical and more professional way to perform this task, any suggestions?
CODE - If using fetch or another library is better practice, please notify
$.getJSON("endpoint1", function (data) {
var datos = data;
$.ajax(
{
url: "endpoint2",
data: { datos: datos },
type: "POST",
dataType: "json",
success: function (cb) {
console.log('success')
}
})
})