ajax请求在本地工作但不在实时服务器上工作

时间:2015-08-26 16:10:59

标签: javascript php jquery ajax laravel

我正在使用laravel 5,并且已经创建了一个简单的ajax请求来触发模型中的函数。

$(document).ready(function(){
    $('.fa-eye').click(function(){
        //we get the data-service value here
        var serviceID = $(this).data('service');

        //every request in laravel requires a token for security, so i set the headers here
        $.ajaxSetup({
            headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
        });

        jQuery.ajax({
            //here i am going to my route and adding the serviceID
            url:'/addwatchlist/' + serviceID,
            type: 'GET',//set the request to GET
            success: function( data ){
                console.log(data);
                //this is simply the serviceID that we sent to the controller seen above
                $('.fa-eye').each(function(){
                    if($(this).data('service') == data){
                        $(this).addClass('watchlisted');
                    }
                });
            },
            error: function (xhr, b, c) {
                console.log("xhr=" + xhr + " b=" + b + " c=" + c);
            }
        });
    });
});

好的,这是我应该打的路线。

Route::get('/addwatchlist/{id}','WatchlistController@addWatchList');

这是它接下来的控制器动作:

public function addWatchList($serviceID)
{
    //simply adds it to the database
    WatchList::saveWatchList($this->userid,$serviceID);

    return $serviceID;
    //this sends back the serviceID back to the ajax success method, the same serviceID that was sent here.
}

好吧就是这样,在我的本地主机上它运行正常没有问题,现在当我将更改推送到我的开发服务器时,我得到以下错误。

enter image description here

enter image description here

任何想法??

0 个答案:

没有答案