Check what error value is in ajax callback

How can I check that the return value of the error is in the ajax callback error:

$.ajax({ url: "myurl", type: 'POST', dataType : "text", data : ({ json : myjson }), success : function(data) { }, error : function() { alert ('error'); } }); 
0
source share
2 answers

Try accessing these options for your part of the ajax call error:

 error: function (request, status, error) { alert(request.responseText); 

Another example:

 error: function(xhr) { if(xhr.status == 422) { alert(parseErrors(xhr)); } else { alert('An error occurred while processing the request.'); } 

They are part of the ajax call, and you separate them with a comma. So a small example:

 $.ajax({ success: function(data) { }, error: function(xhr) { } }); 

Update: Basically, xhr.status is the http status number.

 alert("readyState: "+xhr.readyState); alert("status: "+xhr.status); alert("responseText: "+xhr.responseText); 
+6
source

similar to this question

 error : function(jqXHR, textStatus, errorThrown){ alert(jqXHR.status); } 

http://api.jquery.com/jQuery.ajax/

+1
source

Source: https://habr.com/ru/post/1245877/


All Articles