POST in Reactjs with Object included, how to do?

Asked

Viewed 177 times

0

I need to register for course instructors, in which each instructor will have a course. How do I?

I’m doing it this way and it’s not going:

PS.: the variable name and email receive a variable in String, already the variable course receives the object course.

Code:

cadastraInstrutor(name, email, curso) {
    return fetch('http://localhost:3001/instrutores/',{
        method: "POST",
        body: {name: name, email: email, curso: curso},
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    })
}

After calling the function registerInstrutor, it gives me the error:

Typeerror: Cannot read Property '1' of Undefined

specifically when trying to save the variable stroke

  • Is it the same question https://answall.com/questions/321765 ? Or a different question?

  • I’m already able to register the course, but the instructor needs, in their definitions have the course object. I’m not sure how to do this.

  • It’s returning me this error: Typeerror: Cannot read Property '1' of Undefined

  • In the documentation of MDN has some examples ... But it would be good to ask the question when this error is returning, because apparently you are trying to access the return.

  • How is your server?

  • 1

    body: JSON.stringify({...}),

  • Your doubt is already another, I think it would be interesting to close this question and make a new one with your doubts!

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.