我在 javascript 函数中使用以下代码
$.ajax({
type: "DELETE",
url: '/delprofile',
success:alert("Record deleted."),
error: alert("Record not deleted.")
});
我的路线和功能如下:
public function delprofile (Request $request){
DB::table('education')->where('id','=',7)->delete();
return true;
}
Route::post('/delprofile','ProfileController@delprofile');
查询未执行任何删除。
最佳答案
由于您的 AJAX 将请求方法设置为 DELETE
,因此您必须对路线执行相同的操作。
Route::delete('/delprofile','ProfileController@delprofile');
关于javascript - ajax 不调用 Controller 函数 laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45983824/