0
I have a request in Ajax that consults payments on a third party server, I would like to know how to handle HTTP errors. Example: 'server responded with a status of 404 (Not Found)' This error can happen for several reasons, however it only appears in the log, I would like to treat and shows in an elegant way to the user.
$.ajax(settings).done(function (response) {
console.log(response);
_RecurrentPaymentId = response.Payment.RecurrentPayment.RecurrentPaymentId;
_NextRecurrency = response.Payment.RecurrentPayment.NextRecurrency;
_Status = response.Payment.Status;
});
Hello @Vinicius Gabriel, thank you for answering. A question in function
.fail(function()
can I get the status of the error? Example if it is 400, 404 or 500.– mba
@mba yes, the fail() function has 3 callback parameters that you can use any chaos (jqXHR, textStatus, errorThrown). The first object that is returned 'jqXHR' has several properties, including the status of the request. You can query it using jqXHR.status.
– Vinicius Gabriel
@mba an addendum that I don’t know what version of jQuery you are using, but to be able to use this property you need jQuery 1.5 or higher.
– Vinicius Gabriel
got it. Thank you very much. Hugs.
– mba