![](/img/trans.png)
[英]Uncaught (in promise) SyntaxError: Unexpected end of input at script.js:8:42
[英]Js error: "Uncaught (in promise) SyntaxError: Unexpected end of input"
我遇到了錯誤: Uncaught (in promise) SyntaxError: Unexpected end of input
on try to post refs to my specific express server,你們能幫我嗎?
function create() {
event.preventDefault()
firstName = document.getElementById('firstName').value
lastName = document.getElementById('lastName').value
username = document.getElementById('username').value
password = document.getElementById('password').value
const userInfo = {
firstName: firstName,
lastName: lastName,
username: username,
password: password
}
const config = {
method: "POST",
mode: "no-cors",
body: {userInfo},
headers: {
"Content-Type":"application/json"
}
}
fetch('https://marcelochat.herokuapp.com/create', config)
.then(res => res.json())
.then(resp => {
console.log(resp)
})
}
錯誤在這里: .then(res => res.json())
注意:firstName、lastName、用戶名和密碼常量是輸入值
firstName = document.getElementById('firstName').value
lastName = document.getElementById('lastName').value
username = document.getElementById('username').value
password = document.getElementById('password').value
這個變量是否超出范圍?
如果沒有,試試這個
let firstName = document.getElementById('firstName').value
let lastName = document.getElementById('lastName').value
let username = document.getElementById('username').value
let password = document.getElementById('password').value
並且 config.body userInfo 應該在對象內部嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.