[英]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.