Я хотел бы изучить лучший способ иметь вложенный запрос ajax или множество возможных решений, чтобы получить профессиональный сценарий для приведенного ниже сценария.Любое предложение импровизировать.
// First request starts here
fetch(endpoint1, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"email" : this.state.email,
}),
})
.then((response) => response.json())
.then((responseJson) => {
// Second request starts here
fetch(endpoint2, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"email" : this.state.email,
}),
})
.then((response) => response.json())
.then((responseJson) => {
// Third request starts here
fetch(endpoint3, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then((response) => response.json())
.then((responseJson) => {
// responsejson
})
.catch((error) => {
});
// Third request ends here
})
.catch((error) => {
console.error(error);
});
// Second request ends here
})
.catch((error) => {
console.error(error);
});
// First request ends here
Любыми способами это не проблема, а просто понять и импровизировать.