VM126:1 Uncaught (in promise) SyntaxError: Unexpected token e in JSON at position 0 i think is about my prevent defaut element

Kevin Armache

VM126:1 Uncaught (in promise) SyntaxError: Unexpected token e in JSON at position 0 i think is about my prevent defaut element

sorry for my bad english i not speak english very well

contactForm.addEventListener('submit', (e) => { e.preventDefault();

    let formData = {
        firstname: firstname.value,
        lastname: lastname.value,
        email: email.value,
        message: message.value
 
    }
    //  do fetch with request post of formData


    fetch('https://immo-serkas.herokuapp.com/contact', {
        method: 'POST',
        body: JSON.stringify(formData),
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        }
 })
    .then(res => res.json())
    .then(data => {
        console.log("data : " + data)
        if (data) {
            // show success message
            alert("Email Sent");
            document.querySelector('.contact-form').style.display = 'none'
            document.querySelector('.contact-success').style.display = 'block'
        } else {
            // show error message
            document.querySelector('.contact-form').style.display = 'none'
            document.querySelector('.contact-error').style.display = 'block'
        }
    })
})
Harsh Mangalam

This type of error occur when we parse incorrect json data.

example:-

let jsonData = '{
    "firstName":"harsh",
    lastName:"mangalam"
}'

JSON.parse(jsonData)

here lastName should be "lastName" to prevent from this type of error.

please check your incomming json response.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

Uncaught Promise Rejection SyntaxError: Unexpected token u in JSON at position 0

Uncaught (in promise) SyntaxError: Unexpected token r in JSON at position 0

VM299:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>)

Flask and D3.js error - Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

create-react-app Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 | MongoDB > Express > React.js

Redux app error: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

Error when unit testing: "Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1"

Selectize Uncaught SyntaxError: Unexpected token # in JSON at position 0

Uncaught SyntaxError: Unexpected token u in JSON at position 0

Uncaught SyntaxError: Unexpected token < in JSON at position 0 from Codeigniter response

how to fix Uncaught SyntaxError: Unexpected token o in JSON at position 1

Facing an Uncaught SyntaxError: Unexpected token o in JSON at position 1

Uncaught SyntaxError: Unexpected token o in JSON at position 1 error

[Unhandled promise rejection: SyntaxError: Unexpected token i in JSON at position 7]

Uncaught SyntaxError: Unexpected token , in JSON at position 10

Uncaught SyntaxError: Unexpected token a in JSON at position 2

undefined:1 undefined ^ SyntaxError: Unexpected token u in JSON at position 0

Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) at App.js:18:1 in console

JSON Parse: Uncaught SyntaxError: Unexpected token e

SyntaxError: Unexpected token in JSON at position 0 Express

"SyntaxError: Unexpected token < in JSON at position 0"

NodeJS SyntaxError: Unexpected token in JSON at position 0

"parsererror" SyntaxError: Unexpected token < in JSON at position 0

SyntaxError: Unexpected token ‘ in JSON at position 0

SyntaxError: Unexpected token ' in JSON at position 0

SyntaxError: Unexpected token " in JSON at position 0

Uncaught SyntaxError: Unexpected token U in JSON at position 0 at JSON.parse (<anonymous>) at Response.Body.json