Roy Sijnesael Roy Sijnesael - 1 year ago 168
Ajax Question

Laravel 5.3, Ajax post 500 error

I've been trying to get my POST to work but nothing is really working. I got my UPDATE and DELETE to work, but I'm still getting 500 errors when I'm trying to post something.

I already have my CSRF-TOKEN on top of my file.

//create new task / update existing task
$("#btn-save").click(function (e) {

var formData = {
task: $('#task').val(),
description: $('#description').val(),

//used to determine the http verb to use [add=POST], [update=PUT]
var state = $('#btn-save').val();

var type = "POST"; //for creating new resource
var task_id = $('#task_id').val();;
var my_url = url;

if (state == "update"){
type = "PUT"; //for updating existing resource
my_url += '/' + task_id;


type: type,
url: my_url,
data: formData,
dataType: 'json',
success: function (data){

var task = '<tr id="task' + + '"><td>' + data.task + '</td><td>' + data.description + '</td><td>' + data.created_at + '</td><td>' + data.done + '</td>';
task += '<td><button class="btn btn-warning btn-xs btn-detail open-modal" value="' + + '">Bewerk</button>';
task += '<button class="btn btn-danger btn-xs btn-delete delete-task" value="' + + '">Verwijder</button></td></tr>';

if (state == "add"){ //if user added a new record
}else{ //if user updated an existing record

$("#task" + task_id).replaceWith( task );


error: function (data) {
console.log('Error:', data);

Answer Source

500 means its an internal server error, so something in your php is wrong.

Open your storage/logs/laravel.log and go to your last error. That gives you a clue what the problem is.

(If you have APP_DEBUG=true in your .env, then you should also be able to inspect the error response in the browser.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download