javascript - ajax 不调用 Controller 函数 laravel

标签 javascript php jquery ajax laravel-5

我在 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/

相关文章:

php - PHP数据库错误“CONSTANT_ENCAPSED_STRING”

javascript - 使用 jquery、javascript 的外部系统 slider

javascript - AngularJS 中的动态表单

javascript - (点击)功能不会在 chrome angular 6 中触发

javascript - JavaScript/CSS 应该放在 HTML 页面的底部吗?

php - 查找符合所有条件的记录的通用 ID - 如何构建查询?

php - 使用 cURL 的 Mandrill CA SSL 错误

javascript - 在 JavaScript 中分隔响应中的不同数据

javascript - 无法在 owl-carousel 选项数组中写入 var 值

jquery - 当点击事件在表单之外时,如何使用 FormStrap.IO/Bootstrap Validator 重置验证字段?