Answer the question
In order to leave comments, you need to log in
How to retry a POST request after a failed request?
There is some script (Frontend).
The following lines click on the button on the site.
The button generates a POST request (XHR) https://site.net/ajax/system.php
On average, the request takes 500 ms. Sometimes it happens that this time increases to 17 seconds (for example).
And sometimes the POST request fails and we get 502().
How can the code be improved so that the execution of further code (calling the Result() function) occurs after the end of the POST request. And in case of an error (for example, 502 ()), was the button pressed again?
$('.button_htable input[name=bet]').val(parseFloat(bet).toFixed(8));
var buttonPlayBtn = $('.button_htable .clButtonPlay')[3];
buttonPlayBtn.click();
Result();
Answer the question
In order to leave comments, you need to log in
Use Observables from RxJS
https://github.com/angular/angular/issues/5876#iss...
Catch the error event and it has a timeout status and resend the request on it
check xhr response code
if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
console.log(xhr.responseText);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question