add the same code I gave you for the getStatus request to this payStat method (the part that checks the statuscode == 500 and if so, retries the request.
If you do that, you dont have to put it in the JS code.
public function global_Curl_payStat($data, $url, $try = 1)
{
//dd($_ENV['API_ENDPOINT_NGINX_IP'] . '/' . $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ($_ENV['API_ENDPOINT_NGINX_IP'] . '/' . $url));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Prevents URL cache
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
//Fetch response
$response = curl_exec($ch);
//Get HTTP header status code
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response = json_decode(curl_exec($ch));
curl_close($ch);
if($statusCode == 500 && $try < 5) {
// on HTTP status 500, we'll try up to 5x (dont want any eternal loop)
// let's also wait for a second before trying again
sleep(1);
return $this->global_Curl_payStat($data, $url, ++$try);
}
return $response;
}
If you really want to do this in JS (but I really suggest doing this part in the PHP code)
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.status); // this could then be 500, so you should do the request again.
alert(textStatus);
alert(errorThrown);
}