本文介绍了AJAX - 得到响应主体的成功和错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我道歉愚蠢的问题,但我需要你的帮助。我需要得到有关回应里面 AJAX
信息。
I am apologize for the stupid question, but I need your help. I need to get information about response inside 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 是不工作的momment)
How can I use response body? (documentation Jquary.Ajax is not working at the momment)
推荐答案
在第一个参数错误处理程序 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
}
});
这篇关于AJAX - 得到响应主体的成功和错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!