Level 51
You must paste the code to get some help.
I have created a js file to go with my posts's like and dislike function. Also, I have used Laravel's paginate method to make 10 posts in a single page.
But, I don't know why the javascript doesn't seem to work for the posts from page 2 onwards.
UPDATE: this is my js file:
$('.option1').on('click', function (event) {
var flagL=0;
var flagD=0;
event.preventDefault();
var postIdl = $(this).data("idl");
postIdl= postIdl.substr(1);
var postId2 = 'dc'+postIdl;
var postId1 = 'lc'+postIdl;
if($('.'+postId2).hasClass('active')){
flagD=1;}
if($('.'+postId1).hasClass('active')){
flagL=1;}
$.ajax({
method: 'POST',
url: urlLike,
data: {postIdl: postIdl, _token: token, flagL: flagL, flagD: flagD}
});
$('.'+postId2).removeClass('active');
});
$('.optionx').on('click', function (event) {
var flagL=0;
var flagD=0;
event.preventDefault();
var postIdd = $(this).data("idd");
postIdd= postIdd.substr(1);
var postId1='lc'+postIdd;
var postId2='dc'+postIdd;
if($('.'+postId2).hasClass('active')){
flagD=1;}
if($('.'+postId1).hasClass('active')){
flagL=1;}
$.ajax({
method: 'POST',
url: urlDislike,
data: {postIdd: postIdd, _token: token, flagL: flagL, flagD: flagD}
});
$('.'+postId1).removeClass('active');
});
This is my controller where pagination is used:
public function home()
{
$posts=Depress::orderBy('id','DESC')->paginate(10);
return view('home')->with('posts',$posts);
}
Any help will be appreciated.
Please or to participate in this conversation.