[英]Successful ajax request which goes in error callback instead of success
I have an AJAX request which aims at my API but the response goes in to the error
callback instead of the success
callback and I don't know why.我有一个针对我的 API 的 AJAX 请求,但响应进入
error
回调而不是success
回调,我不知道为什么。 The status response header is the success status (200).状态响应头是成功状态 (200)。 Can you help me please?
你能帮我吗?
I can avoid this issue with the complete
callback and if the status code is 200 or 400 I will display what I want, but it will not solve the real problem.我可以通过
complete
回调来避免这个问题,如果状态代码是 200 或 400,我将显示我想要的内容,但它不会解决真正的问题。 It's actually what I did but it's not the best solution.这实际上是我所做的,但这不是最好的解决方案。
$.ajax({
url: 'http://api.asaplace.v-labs.fr/users/me/cards/' + numCard,
dataType: 'json',
type: 'DELETE',
headers: {
'Authorization': 'Bearer ' + this.state.token
},
success: function() {
console.log("success");
},
complete: function(xhr) {
alert("carte supprimée avec succès");
console.log("error");
},
});
The request请求
我发现“dataType”是在 JSON 中的错误我把它放在 xml 中,它可以工作,谢谢大家的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.