Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 检查ajax回调中的错误值_Jquery - Fatal编程技术网

Jquery 检查ajax回调中的错误值

Jquery 检查ajax回调中的错误值,jquery,Jquery,如何检查ajax回调错误中返回的错误值: $.ajax({ url: "myurl", type: 'POST', dataType : "text", data : ({ json : myjson }), success : function(data) { }, erro

如何检查ajax回调错误中返回的错误值:

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

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

        });  
与此类似


尝试访问这些参数以解决ajax调用的错误部分:

error: function (request, status, error) {
        alert(request.responseText);
另一个例子:

error: function(xhr) {
                if(xhr.status == 422) {
                  alert(parseErrors(xhr));
                } else {
                  alert('An error occurred while processing the request.');
                }
它们是ajax调用的一部分,您可以用逗号分隔它们。举个小例子:

$.ajax({
  success: function(data) {
  },
  error: function(xhr) {
  }
  });
更新: 基本上xhr.status是http状态号

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

抛出错误时,xhr.status的值为0。如果错误是有效的,应该是其他原因吗?请参阅更新部分,以便您可以查看返回的错误消息中的其他内容,以便我们可以查看并将它们放在此处。
alert("readyState: "+xhr.readyState);
alert("status: "+xhr.status);
alert("responseText: "+xhr.responseText);