AJAX and Voting Script (beginner)

272 Views Asked by At

Hey I know that they are many threads about the theme but i need your help because i am a complete noob in AJAX / JQuery stuff ://

I just want that my site doesn´t reload when somebody votes. I have two scripts (an example for thumbsdown)

if (!isset($_COOKIE["vote" . $_GET['id'] . ""])) {
    header("Location: http://localhost/votedown.php?id=" . $_GET['id'] . "");
} else {
    header("Location: http://localhost/video.php?id=" . $_GET['id'] . "");
}

And here votedown.php

include('config.php');
setCookie("vote" . $_GET[ 'id' ] . "", "true", time() + 3600);
mysql_query("UPDATE videos SET `thumbsdown` = `thumbsdown`+1 WHERE id ='" . $_GET[ 'id' ] . "'");
1

There are 1 best solutions below

1
On

Following on from Marabuntas answer; here's a jQuery solution (which is easier to read than the pure JavaScript version):

$.ajax({
    type: 'GET',
    url: 'votedown.php',
    data: // data to put in database here,
    success: function() {
        // callback here
    }
});