我正在尝试在我的网站上实现Googles reCaptchaV3,并且在使用fetch()函数时遇到问题。这就是我到目前为止得到的代码:
function sendData(name, email, captcha) {
const info = JSON.stringify({
name: name,
email: email,
captcha: captcha
});
fetch('/verifycontact', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'mode': 'cors'
},
body: info
})
.then(res => {
alert(JSON.stringify(res));
res.json()})
.then(data => {
alert('msg: ' + data.msg + ', score:' + data.score);
})
}
我尝试对info对象发出警报或console.log(),当我尝试console.log()]时,它会在第一个then。()之前执行console.log()。 >或警告res对象,它只是像下面这样返回空:
,但我得到的还是一样,它是empty。我的** body对象随此到达我的服务器:{}
代码中是否缺少某些内容?也许标题?在我的服务器上,我正在尝试console.log(req.body)
{ success: false, 'error-codes': [ 'invalid-input-response' ] }
我正在尝试在我的网站上实现Google的reCaptchaV3,并且在使用fetch()函数时遇到问题。所以这是我到目前为止得到的代码:function sendData(name,email,captcha){...
我发现了问题。我需要使用bodyParser