Ajax technology, everyone is talking about it, but it has it’s own drawback.
Few advantages for using Ajax on your website:
1. Better and more responsive website and web applications.
2. It uses existing technology that are available in most browsers.
3. It can be use with any server-side language (ASP, PHP) + JavaScript, already in use by many web developers.
4. Ajax integrates perfectly with existing designs and website functionality.
5. Enables immediate tasks like server-side form validation without refreshing the page.
6. Creating simple suggest functionality like Google Suggest.
plus a lot more…
Some of the disadvantages using Ajax:
1. Because pages does not change while it still brings new content or checking a form, can not be easily bookmarked.
2. Search engines may not be able to index all pages available on your website.
3. Back button in browsers doesn’t work as with a normal page.
4. Javascript can be disabled in some browsers client-side making your application non-functional.
Today we will be discussing the solution for creating friendly URLs, using Ajax technology while keeping the functionality for users that have Javascript disabled, and also allow search engines to index your page content as well.
So lets go ahead.
A standard link to another page normally looks like this:
<a href="your-page.php?q=1">text</a>
while an Ajax link is formatted as below:
<a href="#" onclick="ajax-function(’your-page.php?q=1′,’div-to-show-content’); return false;">text</a>
The problem with the Ajax formated link is that search engine can not follow it and if javascript is disabled on the client-side, the link is useless.
A simple way to make the link working no matter what, is by creating a new page that will include your content you were going to load into the existing page, and change your link structure as in the example below:
<a href="your-new-page.php?q=1" onclick="ajax-function(’your-page.php?q=1′,’div-to-show-content’); return false;">text</a>
Adding “return false;” to the “onclick”, if javascript is enabled, the browser will fetch the content into the page section specified without refresh, but if javascript is not available the user will be brought to the new page you just created.
This is just one of the solutions available to make sure you keep the functionality of your website, search engines will index your content, and having a responsive web applications where Javascript available.
Good luck!