0

I am doing a classing ajax ger request:

$.get('/ajax').done(function(data){
   //handle data on success
}).fail(function(jqXHR,status,errorThrown){
    if(jqXHR.status===500){
       //Handle response there
    }
})

I want somehow to be able to get the custom response when my endpoint to ajax request returns error 500.

Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164
  • Note on the duplicate `error` is your proper `fail` with the same parameters passed back. jqXHR here http://api.jquery.com/jQuery.ajax/#jqXHR – Mark Schultheiss Jan 20 '18 at 20:28

2 Answers2

1

I don't think $.get has .error method. See here, http://api.jquery.com/jQuery.get/#jqxhr-object

Instead, you need to handle the error inside the .fail

If you really want to handle using .error then do $.ajax instead

nitte93
  • 1,820
  • 3
  • 26
  • 42
0

Based on Why is jqXHR.responseText returning a string instead of a JSON object? you can get the response data when an error occurs using:

$.get('/ajax').done(function(data){
   //handle data on success
}).fail(function(jqXHR,status,errorThrown){
    if(jqXHR.status===500 && jqXHR.responseText){
      console.err(jqXHR.responseText);
    }
});
Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164