18

我为这个愚蠢的问题道歉,但我需要你的帮助。我需要获取有关内部响应的信息AJAX

$.ajax({
          type: "POST",
          url: '/register',
          data : registerRequestJSON,
          contentType:"application/json",
          success: function(data){
              $("#register_area").text();// need to show success
          },
          error: function(err) {
            $("#register_area").text("@text"); // @text = response error, it is will be errors: 324, 500, 404 or anythings else
          }
    });

如何使用响应正文?(文档 Jquary.Ajax目前不工作)

4

1 回答 1

21

错误处理程序的第一个参数是jqxhr,它具有responseText将给出响应正文的属性。

$.ajax({
          type: "POST",
          url: '/register',
          data : registerRequestJSON,
          contentType:"application/json",
          success: function(data){
              $("#register_area").text();// need to show success
          },
          error: function(jqxhr) {
            $("#register_area").text(jqxhr.responseText); // @text = response error, it is will be errors: 324, 500, 404 or anythings else
          }
    });
于 2013-03-20T07:07:37.780 回答