Level 28
Multiple points here:
- Where is that javascript code? Is it in a blade file? Otherwise that won't work:
'{{ url('/api/menus') }}'
- What does your logfile say what the actual error was? :)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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 or to participate in this conversation.