views:

35

answers:

2

I want to create a page which displays some contents when left navigation menu is clicked. For Eg. When MY FAVOURITE VIDEOS is clicked then the list of the users favourite videos should be displayed on the right side using AJAX. Help me

+1  A: 
<div id="left">
<a href="#" id="favorite">My Favorite Videos</a>
...
</a>

<div id="right"></div>

with:

$(function() {
  $("#favorite").click(function() {
    $("#right").load("favorite_videos.php");
    return false;
  });
});

where favorite_videos.php returns the HTML content to put there.

cletus
+1  A: 

Include jQuery in your page like this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" />

Then hook up the link like this:

$("#myFavouriteVideosLink").click(function () {
    $("#rightSidePanel").load("my_favourite_videos.php");
    return false; // prevent default link action
});

Given that the link and the right side panel has those ID's.

Please note that this isn't an optimal scenario for AJAX, and should probably be handled by normal page requests, to better support browser history and deep linking.

Magnar