SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Location
    San Francisco, CA
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Jquery + PHP - AJAX onclick favorite/unfavorite

    Hello Sitepoint Elite,

    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 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:

    Code:
    --- 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:
    Code:
    --- 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 ---
    Just here for the fun, sun, and of course,
    the Free Arcade Games.

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The JavaScript looks fine.

    Open up firebug (hopefully you already have it) ... Go to the "net" tab and under that go to the "XHR" tab - Does the request show up there?
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •