获取错误在laravel中找不到控制器方法

时间:2014-11-18 02:06:41

标签: javascript php jquery laravel routes

我在laravel的路线有问题。你有什么主意吗?这是我的代码。

我发送变量的jquery:



$('.del').click(function(event){
        event.preventDefault();
        if (confirm("Are you sure?")) {
            var id = $(this).attr('id');
            var actor = $('#actor').val();
            var url = "{{Asset('lesson/delete-chapter')}}";
            var url_dir ="{{Asset('lesson/view')}}"+actor;  //this just url to direct after del
            $.get(url,{id:id},function(data){   
                alert(data);
                $(location).attr("href",url_dir);
            });
        }
        return false;
});



 这是我的路线:

Route::get('lesson/delete-chapter','LessonController@postDeleteChapter');

这是我的控制者:

 public function postDeleteChapter(){
        $id = Input::get('id');

        $less = Lesson::where('chapter_id','=',$id);
        if(count($less)>0){
            $data['re'] = "Please delete lessons in this chapter!";
        }
        else{
            $chapter = Chapter::find($id);
            $less->delete();
            $data['re'] = "Deleted!";
        }
        echo json_decode($data);
    }

由于路线删除会出错,我不知道为什么,你能帮助我吗?非常感谢你。

1 个答案:

答案 0 :(得分:0)

使用url功能代替asset

$('.del').click(function(event){
        event.preventDefault();
        if (confirm("Are you sure?")) {
            var id = $(this).attr('id');
            var actor = $('#actor').val();
            var url = "{{url('lesson/delete-chapter')}}";
            var url_dir ="{{url('lesson/view')}}"+actor;  //this just url to direct after del
            $.get(url,{id:id},function(data){   
                alert(data);
                $(location).attr("href",url_dir);
            });
        }
        return false;
});