Register | Log in | RSS channel for codegravity.com homepage Bookmark!

284/2NEW projects | 71 services | 215 websites | 834/3NEW freelancers | 2126 topics | advertise



Login:



Forgot your password?
Forgot your username?
Create an account
JoomlaWatch Agent

Users

Most active users today from total of 109:
Peerke, garikello, jakkrit, dayanand, andrew_saber, giakhanh, mohalb, carmachhh, fguyon, dfireablaze, phoeker, ozedfr, boho, ashish_php, blackie, amoluca, JDev, tinytim007, Pascale, mayas_salman


19.9%United States United States
17.9%India India
9.3%Germany Germany
5.5%Russian Federation Russian Federation
4.4%United Kingdom United Kingdom
4.3%France France
4%Australia Australia
3.8%Netherlands Netherlands
3.8%Poland Poland
3.7%Italy Italy

Today: 976
Yesterday: 1402
This Week: 5266
Last Week: 8869
This Month: 2378
Last Month: 37593
Total: 117058


Partners:

HTML5, CSS3, SVG, tutorials

Freelance ColdFusion, Flex, PHP

Olejomalby, abstraktne obrazy

Camping Europe

WinAsm Studio

Vyšné Ružbachy

Sochy, Reštaurovanie

R.E.M.

Valid XHTML 1.0 Transitional

RSS feed:

Statistics:
Search Engine Genie Promotion Widget
Home

Practical usage of AJAX on this website

ajax

 

I found a great CSS dropdown menu on a website http://www.cssplay.co.uk/menus/drop_variation.html

It allows you to include the dropdown menu as one you can see on the top of this website. One great advantage is that it's in a plain HTML with the usage of CSS styling and therefore no javascript coding is required.

Ok, so I made a module that generates the set of HTML links from the Joomla CMS which are then transformed into this nice menu.
Every page of my website usually contains less than 100 links (internal+external) because I want the pages to be the search engine friendly.  But using this feature the number of links on every webpage increased to 200 or so.

Then I got the idea. Why not to use the AJAX to modify the webpage when it's loaded ?

The principle is simple:

  • The page loads with the empty <div id="menu"> </div> 
  • After the page is loaded, there is a javascript executed that calls the menu.php serverside script and modifies the DOM (document object model) of this webpage - the content of empty <div> element.
  • When you open the http://www.codegravity.com/menu.php manually, you can see what the content of the <div> element would be like

This way I can have the page optimized for the search engines and still use more than 100 links on every webpage. (Search engine bots usualy index a webpage as a single HTML and don't care about the javascript calls. They see your webpage as when you open it in a LYNX or another simple HTML text browser).

ajax menu
A CSS menu loaded by the AJAX approach


Here's the HTML code:

<div class="menu" id='ajaxmenu'></div> 
<!-- the div element where we want the menu to be loaded -->
<script> 
function execute() {
if (xmlHttp.readyState == 4) {
	if 	(xmlHttp.status == 200) { 
//when there is the HTTP response code 200 (what means OK)
		document.getElementById("ajaxmenu").innerHTML = xmlHttp.responseText;
//this is the main "trick", we are searching for the "ajaxmenu" element
//and filling up it's content through the innerHTML function
	}
}

}
// this is a non-unified way how to obtain a XMLHttpRequest object 
// (the IE's got it's own way to do it)
if (window.ActiveXObject) {
	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // for internet explorer
}
else if (window.XMLHttpRequest) {
	xmlHttp = new XMLHttpRequest(); // other browsers
}
xmlHttp.open("GET","http://www.codegravity.com/menu.php"); 
//here we are making a XMLHttpRequest to fetch the result of the
//serverside menu.php script
xmlHttp.onreadystatechange = execute;  
//when it's completed, we call the function execute you can see above
xmlHttp.send(null);

</script>

 

This approach is nothing new, the aim was just to show a simple example and to share my experiences with you.

I hope you enjoyed it and feel free to comment!

Thank you

 

Comments  

 
0 #1 paul 2007-07-27 17:11
good tutorial
Quote
 

Add comment


Security code
Refresh

No Tweets

Add URL of a programming website
register as a freelancer
submit your project
open freelance projects you can work on
webmaster resources
write paid blog posts about programming - tips and articles
bugs and features

Recommended: (advertise)
Download Joomlawatch 1.2.12


Register as a Freelancer -
Submit your project experiences, programming languages and your other skills

Green Geeks Hosting -
World's best selling green web hosting

HostMonster.com -
best cheap Joomla Web hosting. Website joomlawatchdemo.com is hosted by them with domain for $6,95/mo.

FastDomain.com -
Fast Domain hosting. Hostmonster alternative. Also for $6.95/month.


Freelancers, create paid articles
-
Looking for freelancers with experiences in Java to write paid articles on their experiences


Advertise Here
-
Promote your services and get the new customers from the community of webmasters / programmers visiting CodeGravity.com


Outsource your project
-
Submit your project description with all the requirements to more than 600 freelancers from around the world for FREE.



News from Twitter:
No Tweets
RSS Feeds:new

rss Freelance
rss Projects
rss Forum
rss Resources

Popular:
MathGuard
download mathguard
Random screenshot:

linoopz15.jpg


Poll

At what price would you purchase JoomlaWatch ad-free license?
 
Privacy policy | Advertise | Donate | Doucovanie Nemcina
Joomla Visitors Google Map
Loading map...
Joomla Visitors Google Map
Visitors Google Map Agent

Locations of visitors to this page


©2003-2010 Codegravity.com