$.ajax({
type: 'POST',
url: api_url+'client/'+client.id+'.json',
data: {
_method: 'delete',
id: client.id
},
success: function(data) {
$('#delete-client').html('Success');
},
error: function(data) {
$('#delete-client').css('color', 'red');
$('#delete-client').html('Error');
}
});
On the error: function the jquery would recieve this json object with a 500 header status
{"errors":{"code":777,"message":"Method requested does not yet exist","data":[]}}
however if I use data.errors.message it doesnt show the error there. It shows a huge object with different events in chromes developer box when I console.log the return object its using
FIXED
var error = jQuery.parseJSON(jqXHR.responseText);
$('#delete-client').html(error.errors.message);
Example: We are going to see how to use AJAX fail() methods to handle the error in the HTTP requests. The fail() callback takes 3 parameters where the first parameter is a JSON error object, the second parameter is given a reason in text format and the last parameter is for the error thrown by the HTTP request.
What is AJAX success? AJAX success is a global event. Global events are triggered on the document to call any handlers who may be listening. The ajaxSuccess event is only called if the request is successful. It is essentially a type function that's called when a request proceeds.
The ajax() method in jQuery is used to perform an AJAX request or asynchronous HTTP request. Parameters: The list of possible values are given below: type: It is used to specify the type of request. url: It is used to specify the URL to send the request to.
add : dataType:"json"
...............
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With