Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
API - Uncaught (in promise) SyntaxError: Unexpected end of input

I have basic html file which include input and button. I want to take this input value and send to api. Api accepts POST requests. But when I click change data button, it gives Uncaught (in promise) SyntaxError: Unexpected end of input

Here is my javascript code -

let input = document.querySelector("input")
let button = document.querySelector("button")



button.addEventListener("click", () => {
    let number = Number(`${input.value}`);
    console.log(number)
    async function postData(url = 'https://us-central1-smartkarabakh.cloudfunctions.net/main/main/setLedData', data = {}) {
        // Default options are marked with *
        const response = await fetch(url, {
          method: 'POST', // *GET, POST, PUT, DELETE, etc.
          mode: 'no-cors', // no-cors, *cors, same-origin
          headers: {
            'Content-Type': 'application/json'
            // 'Content-Type': 'application/x-www-form-urlencoded',
          },
          redirect: 'follow', // manual, *follow, error
          referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
          body: JSON.stringify(data) // body data type must match "Content-Type" header
        });
        return response.json(); // parses JSON response into native JavaScript objects
      }
      
      postData('https://us-central1-smartkarabakh.cloudfunctions.net/main/main/setLedData', { ledEnergy: number })
        .then(data => {
          console.log(response.json()); // JSON data parsed by `data.json()` call
        });
})
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda