ajax post in laravel 5 return error 500 (Internal Server Error)

后端 未结 12 1053
不知归路
不知归路 2020-11-29 05:13

this is my test ajax in laravel 5 (refer below)

$(\"#try\").click(function(){
    var url = $(this).attr(\"data-link\");
    $.ajax({
        url: \"test\",
         


        
12条回答
  •  盖世英雄少女心
    2020-11-29 05:46

    I guess this has been solved by now but still the best thing to do here is to send the token with your form

    {!! csrf_field() !!}
    

    and then in your ajax

    $("#try").click(function(){
    var url = $(this).attr("data-link");
    $.ajax({
        url: "test",
        type:"POST",
        data: { '_token': token, 'someOtherData': someOtherData },
        success:function(data){
            alert(data);
        },error:function(){ 
            alert("error!!!!");
        }
    }); //end of ajax
    });
    

提交回复
热议问题