Laravel 5.1 - 当站点在线时,Ajax错误POST 500

时间:2015-12-02 11:00:06

标签: php jquery ajax laravel-5.1

我的laravel 5.1网站上的AJAX调用存在问题。

当我在本地运行网站时,它没有任何问题。但是当我在线运行网站时出现错误

error

网页链接为enter image description here

这里是我用于ajax函数的代码

$('.articleFavo').click(function(e){
    e.preventDefault();
    var userid= $('input[name=userID]' ).val();
    var functionType = 'favorite';
    var articleid=$('input[name=articleId]').val();
    var token=$('input[name=_token]').val();

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

    $.ajax({
        url:articleid,
        type: "post",
        data:
        {
            'functionType': functionType,
            'user_id': userid,
            'article_id': articleid,
            '_token': token
        },
        success: function(){
            console.log(articleid);
            $('#favoriteBtn'+ articleid).css({display: 'none'})
            $('#unfavoriteBtn'+ articleid).fadeIn();
        }
    });
});

这是我的PHP代码

    elseif($functionType == 'favorite')
    {
        $user_id = Auth::user()->id;
        $article_id = input::get('article_id');

        $results = DB::select("select *
                       from favorites
                       where user_id = $user_id AND article_id = $article_id");
        $articleDetails = DB::select("select *
                       from articles
                       where id = $article_id");

        if ($results == null){
            $favorite = new favorite();
            $favorite->user_id = $user_id;
            $favorite->article_id = $article_id;
            $favorite->save();

            $notification = new Notification();
            $notification->user_id = $articleDetails[0]->user_id;
            $notification->save();
        }else{
            echo "You already added this as a favorite!";

}             }

0 个答案:

没有答案