且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AJAX - 得到响应主体的成功和错误

更新时间:2022-06-05 09:10:03

在第一个参数错误处理程序 jqxhr ,它具有这样的性质的responseText 这将给响应主体。

The first param to error handler is jqxhr, it has the property responseText which will give the response body.

$.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
          }
    });