简体   繁体   English

成功的ajax请求进入错误回调而不是成功

[英]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请求

enter image description here在此处输入图片说明

我发现“dataType”是在 JSON 中的错误我把它放在 xml 中,它可以工作,谢谢大家的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ajax中的服务器响应是错误功能而不是成功 - server response in ajax goes in error function instead of success 是否存在可以在ajax请求中调用成功和错误回调函数的情况? - Is there a scenario in which the success & error callback function could be called within an ajax request? Ajax请求。哪个回调首先完成或成功执行? - Ajax request. Which callback is executed first complete or success? jQuery Ajax如何知道哪个响应数据与哪个成功回调一起使用? - How does jQuery Ajax know which reponse data goes with which success callback? Rails完成200 OK,但是$ .ajax()调用“错误”回调而不是“成功” - Rails completed 200 OK but $.ajax() calling 'error' callback instead of 'success' Ajax 请求返回 200 OK,但触发了错误事件而不是成功 - Ajax request returns 200 OK, but an error event is fired instead of success 通过AJAX POST成功发送了电子邮件,但触发了错误回调而不是成功回调 - E-mail sucessfully sent via AJAX POST but error callback triggered instead of success callback 使用jQuery AJAX与asp.net webservices总是会出错:而不是成功: - using jQuery AJAX with asp.net webservices always goes to error: instead of success: Ajax JSON请求始终转到.fail回调 - Ajax JSON request always goes to .fail callback 重试AJAX请求将忽略成功回调 - Retrying AJAX request ignores the success callback
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM