Jump to content

implement like button increment in php ajax


ochen_jamir

Recommended Posts

Hi All,

 

I am implementing a facebook like "Like" button counter so everytime a user clicks on the button, via an ajax call a DIV tag besides it updates it from the db (see logic of the code below). However it isn't working. Please see all codes below:-

 

I have copied the code from the w3schools php ajax tutorial page and made some modifications for the button click call.

 

javascript:


MySQL:


HTML:

<img src="./images/like.jpg" style="cursor:hand;" onclick="likeAJAX(<?php echo $_GET['val']; ?>)"><?php echo $likeVal; ?> people like this</span>

Seems like the onclick isn't working, i have tried putting an alert on the javascript function but it isn't getting triggered. Is it some typo/syntax error with the javascript function onclick not being able to recognize the php variable being called.

 

Regards,

 

Ochen

Link to comment
Share on other sites

Start by opening your browser's developer tools and checking the console, if there are any error messages they will be listed there. Also, check the HTML that gets outputted to make sure that things are formatted correctly after PHP runs.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...