我一直在試圖讓我的POST工作,但沒有什麼是真正的工作。我有我的更新和刪除工作,但我仍然收到500錯誤,當我試圖發佈的東西。Laravel 5.3,Ajax後500錯誤
我的文件上已經有了我的CSRF-TOKEN。
//create new task/update existing task
$("#btn-save").click(function (e) {
e.preventDefault();
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;
}
console.log(formData);
$.ajax({
type: type,
url: my_url,
data: formData,
dataType: 'json',
success: function (data){
console.log(data);
var task = '<tr id="task' + data.id + '"><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="' + data.id + '">Bewerk</button>';
task += '<button class="btn btn-danger btn-xs btn-delete delete-task" value="' + data.id + '">Verwijder</button></td></tr>';
if (state == "add"){ //if user added a new record
$('#tasks-list').append(task);
}else{ //if user updated an existing record
$("#task" + task_id).replaceWith(task);
}
$('#frmTasks').trigger("reset");
$('#myModal').modal('hide')
},
error: function (data) {
console.log('Error:', data);
}
});
});
});
500錯誤會來自你的PHP代碼,而不是在這裏列出的JavaScript代碼。檢查你的錯誤日誌,找出它爲什麼投擲500. – aynber
錯誤500似乎是權限錯誤。嘗試檢查文件的權限。 –
你可以發佈你的Laravel代碼,包括你定義這些URI的路線嗎? – tptcat