我的laravel 5.1网站上的AJAX调用存在问题。
当我在本地运行网站时,它没有任何问题。但是当我在线运行网站时出现错误
这里是我用于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!";
} }