I was sending a request to a controller using Ajax but every time i got this errors:
these 2 errors when i refresh the page:
1) Uncaught ReferenceError: $ is not defined
2) Uncaught ReferenceError: Holder is not defined
and this error when i send request:
jquery-3.3.1.min.js:2 POST localhost/.. 405 (Method Not Allowed)
send @ jquery-3.3.1.min.js:2
ajax @ jquery-3.3.1.min.js:2
(anonymous) @ 0:221
dispatch @ jquery-3.3.1.min.js:2
y.handle @ jquery-3.3.1.min.js:2
my code:
$.ajax({
type:'POST',
data:
{
"_token":$("input[name=_token]").val(),
'question_id':question_id,
'user_id':user_id
},
href:"{{route('favorites.reds')}}",
success: function (data) {
console.log(data);
}
})
the route:
Route::post('/questions/reds', "FavoritesController@addToReds")->name('favorites.reds');
Inputs:
<i class="fa fa-heart" style="margin-right: 100px; cursor: pointer; " aria-hidden="true">
<input type="hidden" value="{{$question->id}}" class="question_fav">
<input type="hidden" value="{{Auth::user()->id}}" class="user_fav">
</i>
Can anyone figure this out?
Looks like you may be using incorrect syntax in your $.ajax
function. Switch href:"{{route('favorites.reds')}}"
to url:"{{route('favorites.reds')}}
and see it that helps.