Status 500, Internal Server Error in api using fetch

Posted 1 month ago by andersonmichel

I have a function in a Vue instance, and I'm trying to update my data by api. Using Postman I can test and it works pretty fine. But using Javascript it dont works, and I can see in console a status 500 "Internal Server Error". Can someone help my with my code?

save(){
                const url_save = '{{ url('/api/menus') }}';
                var metodo = 'POST';
                if(this.menu.id != ''){
                    metodo = 'PUT';
                }
                var post = {
                    id: this.menu.id,
                    nome: this.menu.nome,
                    itens: this.menu.itens,
                    localizacoes: this.menu.localizacoes,
                }; alert(JSON.stringify(post));
                var options = {
                    method: metodo,
                    body: JSON.stringify(post),
                    headers: {
                        'Accept': 'application/json',
                        'Content-Type': 'application/json'
                    }
                };
                console.log(options)
                fetch(url_save, options).then(res => {console.log(res)
                    return res.json();
                }).then(json => {
                    alert("O menu foi salvo com sucesso!");
                }).catch(err => console.error('Caught error: ', err));
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.