Answer the question
In order to leave comments, you need to log in
Will the request be terminated if there is a redirect to another page?
There are two requests sent from the frontend.
Request #1 goes to our server, is processed and sent to a third-party server. We do not expect a response from this request on the frontend.
Request number 2 goes to our server, is processed, we send a response to the frontend, then a redirect to another page.
Both requests are asynchronous. Will Request #1 be terminated if the redirect occurred faster than the request from our server to the third-party server could be sent?
Frontend:
request1();
request2();
function request1() {
$.ajaxSetup({
headers: { 'X-CSRF-Token' : '{!! csrf_token() !!}' }
});
$.ajax({
type: "POST",
url: "{{ url() }}/url-1",
data: data,
dataType: 'json',
error: function (data) {
console.log(data)
},
success: function (data) {
// do nothing
console.log(data)
}
}); // End AJAX
}
function request2() {
$.ajaxSetup({
headers: { 'X-CSRF-Token' : '{!! csrf_token() !!}' }
});
$.ajax({
type: "POST",
url: "{{ url() }}/url-2",
data: data,
dataType: 'json',
error: function (data) {
console.log(data)
},
success: function (data) {
// redirect
window.location.href = newUrl;
}
}); // End AJAX
}
{
$listID = 2;
$segment = parse_url($request->headers->get('referer'))["path"];
if ($segment == '/some-url') {
$listID = 8;
}
$client = new Client();
$res = $client->request('POST', 'XXX', [
'form_params' => [
'api_key' => 'XXX',
'actid' => 'XXX',
'api_action' => 'XXX',
'api_output' => 'json',
'p[listID]' => $listID,
]
]);
echo $res->getBody();
}
Answer the question
In order to leave comments, you need to log in
Will Request #1 be terminated if the redirect occurred faster than the request from our server to the third-party server could be sent?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question