I need to clear the following doubt. I want to make 2 ajax requests, the problem is that I make the request 1 (I get a data) and I need to pass that data to the request 2. I have done the following:
ERROR Doing it this way, I get cors error. If I do the ajax on the outside I can not get the data of the request 1
POSSIBLE SOLUTION When obtaining the data of petition 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 carry out this task, any suggestions?
CODE - If a fetch or other library is best 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')
}
})
})