【问题标题】:Js error: "Uncaught (in promise) SyntaxError: Unexpected end of input"Js错误:“未捕获(承诺)SyntaxError:输入意外结束”
【发布时间】:2021-01-09 18:54:08
【问题描述】:

我遇到了错误:Uncaught (in promise) SyntaxError: Unexpected end of input 尝试将 refs 发布到我的专用快递服务器,你们能帮帮我吗?

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、username 和 password 常量是输入值

【问题讨论】:

    标签: javascript express post


    【解决方案1】:
        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 应该在对象内部吗?

    【讨论】:

      猜你喜欢
      • 2020-06-26
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 2017-01-05
      • 2019-01-17
      相关资源
      最近更新 更多