I want to implement like and dislike buttons in a webpage. I know how to do it if the voting sent the user to another page, but I want:
1. The webpage to stay the same, no redirecting
2. The MySQL database to update
3. To disable the like and dislike buttons once the user has voted.
I have no idea how to do this. Does anyone have the answer or a tutorial I could read?
If you know how to do the mysql/php part by itself - you just need to learn AJAX. Search on google ajax tutorials - or jquery ajax tutorials
This can be done in php. You just set the action of the form to the same file. E.g. If the file is called index.php:
<form action="index.php" method=get>
<input type=submit name="vote" value="like">
<input type=submit name="vote" value="dislike">
If you do not want to use a form, you can simulate it with anchors:
In either case you need to allow for the url variable vote being NULL when index.php is first displayed.
That's still redirecting, not leaving the webpage is making an ajax request... OP stated he/she knows how to do this already - but not how to do it without leaving the current page
Originally Posted by jedaisoul
Thanks, Mistin! I will check on this AJAX thing
Jedaisoul, Mistin is right, that needs redirecting, but thanks
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)