简体   繁体   English

Ajax查询中的Laravel错误500

[英]Laravel error 500 in Ajax query

I have a code: 我有一个代码:

function addProductInCart() {
    var product = 1;

    var token  = $('meta[name=_token]').attr('content');
    $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': token }});



    $.ajax({
        type: "POST",
        url: "add_to_cart",

        data: {"product": product, '_token':token},
        success: function (result) {
            console.log(result);
        }
    })
}

I have a route: 我有一条路线:

Route::post('/add_to_cart', 'AjaxController@addProduct');

I have error 500. 我有错误500。

I can not understand a reason of error. 我无法理解错误原因。

I found issue. 我发现了问题。 It's so stupid reason of error. 这是错误的愚蠢原因。 I placed my php method outside class. 我把我的php方法放在课外。 And was error, because class AjaxController did not have method "addProduct". 并且是错误的,因为类AjaxController没有方法“ addProduct”。 Thanks all for the help. 谢谢大家的帮助。 Sorry what I am so stupid) 对不起,我这么傻)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM