AJAXify your Website: Difference between revisions


(New page: You can AJAXify your Viviti site, or make all of your pages load via [http://www.w3schools.com/Ajax/Default.Asp AJAX] by adding some simple JavaScript code utilizing the built in [http://j...)
 
mNo edit summary
Line 1: Line 1:
You can AJAXify your Viviti site, or make all of your pages load via [http://www.w3schools.com/Ajax/Default.Asp AJAX] by adding some simple JavaScript code utilizing the built in [http://jquery.com/ jQuery].
You can AJAXify your Viviti site, or make all of your pages load via [http://www.w3schools.com/Ajax/Default.Asp AJAX] by adding some simple JavaScript code utilizing the built in [http://jquery.com/ jQuery].


Since the main content area of Viviti is inside a div#location_0, all you have to do is hook into the [[Primary Navigation]] links and use the [http://docs.jquery.com/Ajax/load jQuery load function] to replace the contents of #location_0 on the current page with the contents of #location_0 on the target page. Adding a [http://docs.jquery.com/Effects/slideUp slideUp]/[http://docs.jquery.com/Effects/slideUp slideDown] with some callbacks makes it have a nice transition as well.
Since the main content area of Viviti is inside a '''div#location_0''', all you have to do is hook into the [[Primary Navigation]] links and use the [http://docs.jquery.com/Ajax/load jQuery load function] to replace the contents of '''#location_0''' on the current page with the contents of '''#location_0''' on the target page. Adding a [http://docs.jquery.com/Effects/slideUp slideUp]/[http://docs.jquery.com/Effects/slideUp slideDown] with some callbacks makes it have a nice transition as well.





Revision as of 15:01, 10 June 2009

You can AJAXify your Viviti site, or make all of your pages load via AJAX by adding some simple JavaScript code utilizing the built in jQuery.

Since the main content area of Viviti is inside a div#location_0, all you have to do is hook into the Primary Navigation links and use the jQuery load function to replace the contents of #location_0 on the current page with the contents of #location_0 on the target page. Adding a slideUp/slideDown with some callbacks makes it have a nice transition as well.


The JavaScript to do this is:


$j('#primary_navigation li a').click(function() { loadPage( $j(this).attr('href')); return false; });

function loadPage( page ) { 
  $j('#location_0').slideUp(300, function() { 
    $j('#location_0').load( page + ' #location_0 > *', function() { $j('#location_0').slideDown(300);}); 
  });
}


Example:

Viviti user Yuao's site is currently configured to load pages via AJAX:

http://showcase.imyuao.com/