在Laravel中使用ajax时出现404 Not Found错误

时间:2017-05-30 07:44:01

标签: ajax laravel

我已经设置了评论板,并使用ajax通过路由发送用户输入的内容以及其他相关数据。但是,每当我尝试这样做时,控制台都会向我发送404错误。

enter image description here

这是ajax代码

if ($('#discussionBoardNewComment').val()) {
  $.ajax({
    type: "POST",
    url: "/project/identification/comment/{{$project}}",
    data: {
        comment: $("textarea[name='discussionBoardNewComment']").val(),
    },
}

这是我的路线:列表的结果 enter image description here

告诉我你还有什么需要

1 个答案:

答案 0 :(得分:1)

显然这不是你的道路。尝试使用action()生成您的网址。

if ($('#discussionBoardNewComment').val()) {
  $.ajax({
    type: "POST",
    url: "{{action('ProjectsController@comment', ['project' => $project->id])}}",
    data: {
        comment: $("textarea[name='discussionBoardNewComment']").val(),
    },
}