Find services - Debt Consolidation - Hindi movies, hindi songs - Reference 2007 - Debt Consolidation

PDA

View Full Version : Jquery + PHP - AJAX onclick favorite/unfavorite


dlow123
Oct 24th 2008, 11:33 pm
Hello DPers,

I am trying to build out a quick and dirty favorite feature for my site using Jquery and a little bit of ajax.

Similar to the one used here (http://www.gamegum.com/game/3082/the-strangers-2/) on this arcade site.

So far I have tried using a simple php GET request as well as a POST request, nothing seems to work.

Here is the Javascript code I have thus far:


--- JAVASCRIPT ---

$(document).ready(function() {

favGame();

// Favorite Link //
function favGame() {

$("a.arfavorite").click(function() {
$.get("favorites.php", {gid: gid, ar: ar}, function() {
alert("it all worked");
});
return false;
});
}

});

--- JAVASCRIPT ---


Here is the PHP code I have thus far:

--- PHP ---

if (!isset($favorites[$game['id']])) {
echo "<a title='Add Favorite' class='arfavorite' href='profile/favorites.php' rel='nofollow'>Add To My Favorites</a>";
} else {
echo "<a title='Remove Favorite' class='arfavorite' href='profile/favorites.php' rel='nofollow'>Remove From My Favorites</a>";
}

--- PHP ---


:confused: