D
D
Denis2020-04-24 13:03:21
JavaScript
Denis, 2020-04-24 13:03:21

TypeError: update.json is not a function?

When sending, a TypeError error pops up: update.json is not a function, if you refresh the page, the data is still updated, the fetch works. But with this error... const result = await update.json();

async function update() {
    const id = document.getElementById('id ').value,
        title = document.getElementById('title ').value,
        body = document.getElementById('body ').value;
    if (title == '' || body == '') {
        return;
    }

    const data = {
        title: title,
        body: body
    };

    const update = fetch(`http://pathTo/up/${id}`, {
        method: 'PATCH',
        body: JSON.stringify(data)
    });

    const result = await update.json();

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Loli E1ON, 2020-04-24
@Drumsid

const update = await fetch(`http://pathTo/up/${id}`, {
        method: 'PATCH',
        body: JSON.stringify(data)
    });

    const result = await update.json();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question