Laravel Ajax 调用 post/put 给出 500/404 内部服务器错误,但在本地服务器中工作


laravel ajax call post/put give 500/404 internal server error but works in local server

我真的不明白这一点:

   jQuery('.myCheckbox').click(function() {
        if($(this).is(':checked')) 
        {
            $.ajax ({
                type: "POST",
                url: "comparecustom",
                data:  {
                    'product_id':  prdidtable,
                    'term_id':     checkboxData,
                    'sort_list_id': sort_list_id
                },
                success: function(data) {
                    console.log(data);
                },
                complete : function(){  // this will be called even if our request fail, success etc
                }
            });
            $('.mybestall_'+checkboxData).prop('checked',false);
        }
        else if($(this).not(':checked')) 
        {
            $.ajax ({
                type: "POST",
                url: 'comparecustom',
                data:  {
                    'product_id':  prdidtable,
                    'term_id':     checkboxData,
                    'delete_data': delete_data
                },
                success: function(data) {
                    console.log(data);
                },
                complete : function(){  // this will be called even if our request fail, success etc
                }
            });
        } 
    });

我的路线:

Route::post('comparecustom', array('before' => 'csrf', 'uses' => 'compares@comparecustom'));

我的控制者:

if(Request::AJAX())
        {
}

In 在本地主机中工作正常,但是当我转移到实时服务器时,分别返回 POST/PUT 500/404 错误。我已经尝试了许多不同的方法,仍然找不到解决方案。

它在本地主机中完美运行,为什么在实时服务器中不起作用?

请帮忙?csrf_token?

可能是我需要与 Ajax 调用一起传递的csrf_token:我也试过没有运气

好的!我已经通过在我的路线中使用"/"来解决它。开头添加了"/":

Route::p ost('/products/(

:any)/comparecustomdata', array('uses' => 'compares@comparecustomdata'));

所有其他路由都没有"/"。 这让我很困惑。

所以问题解决了。

谢谢大家的帮助