简体   繁体   English

收到200状态代码而不是201

[英]Receiving a 200 status code instead of a 201

I'm sending a simple ajax call to an api that will store the email / url I send it. 我正在向API发送一个简单的Ajax调用,该API将存储我发送的电子邮件/网址。

 const emailAnswer = this.state.emailAnswer; const emailText = `${emailAnswer}`; const fullurl = window.location.href; const fullurlText = `${fullurl}`; console.log(fullurlText); $.ajax({ url: '/email', method: 'POST', data: { email: emailText, url: fullurlText }, statusCode: { 200: function() { console.log('you got a 200'); }, 201: function() { console.log('saved'); }, 400: function() { console.log('email not posted'); } }, }).done(function() { console.log('done'); }); 

I'm getting a 200 status code back when I submit this information to the api instead of a 201 status code. 当我将此信息提交给api时,我得到的是200状态代码,而不是201状态代码。

What am I missing here? 我在这里想念什么?

Did you check that on your backend that the status code to be sent back is for sure supposed to be 200? 您是否在后端检查过发送回的状态码确定为200?

ie res.status(200).send('stuff') 即res.status(200).send('stuff')

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

相关问题 如何在Frisby Test中验证状态码是200还是201 - How to verify if either 200 or 201 status code in Frisby Test Python Flask Web服务器未收到JSON Ajax POST请求,服务器返回HTTP 200 OPTIONS而不是201 POST - Python Flask webserver not receiving JSON ajax POST requests, server returns HTTP 200 OPTIONS instead of 201 POST 将HTTP状态响应设置为201时返回200 - HTTP Status response returning 200 when I have set it to 201 如何在 Javascript 中设置状态码 201? - How to set status code 201 in Javascript? MongoDB Atlas触发器—收到“ StitchError:HTTP请求失败:意外状态代码:预期= 200,实际= 415”错误 - MongoDB Atlas Trigger — Receiving a “StitchError: HTTP request failed: unexpected status code: expected=200, actual=415” error 接收非 200 状态代码时,如何防止 WebLOAD wlHttp 模块中止回合? - How to prevent WebLOAD wlHttp module from aborting round when receiving non-200 status code? 即使出现“内部错误”,Rest API 也会返回状态代码 201 - Rest API return status code 201 even with a "internal error" 为什么即使未提供令牌,我的测试也会收到状态 200? - why is my test receiving status 200 even though token is not provided? 异常捕获到状态代码为200的Get() - Get() with status code 200 caught in the exception UrlFetchApp POST无法正常工作,但返回状态码:200 - UrlFetchApp POST not working, but returning Status Code: 200
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM