0

How can I check what the error value returned is in ajax callback error :

$.ajax({
            url: "myurl",       
            type: 'POST',
            dataType : "text",
            data : ({
                json : myjson
            }),
            success : function(data) {

            },
   error : function() {
                alert ('error');
    } 

        });  
4

2 回答 2

8

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

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 you seperate them with a comma. So a little 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);
于 2012-06-18T22:41:36.757 回答
1

similar to this question

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

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

于 2012-06-18T22:32:46.950 回答