Learn AJAX

Asynchronous JavaScript And XML: A to Z blog…

Archive for the ‘Technology’ Category

AJAX Basics

Posted by Lasantha Samarakoon on August 20, 2009

Today I’m going to talk to you about, AJAX Basics. As the previous post, you can see that in the AJAX model, data transfers happen via the AJAX Engine. So the very first thing we have to do is to understand and create this AJAX engine. AJAX engine is just an object which is called as XMLHttpRequest.  By creating an object of this XMLHttpRequest, you can communicate with the web server through JavaScript.

But when you try to create the object, Cross-Browser Compatibility will be an issue. Because you can’t create the object in non-Internet Explorer, in the same way as in Internet Explorer. That’s occurred because in IE, XMLHttpRequest come as an ActiveXObject, but in non-IE browsers it comes in native handler.

So here is how I going to create “XMLHttpRequest” object.

Creating XMLHttpRequest object

Creating XMLHttpRequest object

OK.. this is the way to create an XMLHttpRequest object. This code snippet will be working on Microsoft Internet Explorer as well as Non-IE browsers such as Mozilla Firefox, Opera, Safari or anything. By using this httpvariable, we can transmit data with the web server. I hope to show you an “Hello World” example in the next post.

Posted in Technology, Uncategorized | Tagged: , , , , | 2 Comments »

Need of AJAX…

Posted by Lasantha Samarakoon on August 19, 2009

Remind a situation where you used Google to search something. You visited Google, entered the keyword, and file clicked “Search”, the page went blank and loaded the new page with your search results. So in this situation, when you click “Search”, the browser navigated from one page to another. So the total page reloaded. If the second page contains only few kbytes, and the content in the previous page will no longer required, then this won’t be a big problem. But if you have a slow internet connection, and you are viewing a photo gallery in Facebook or something, and you clicked on a thumbnail to enlarge it, the page vanished and finally you are end up with only the larger one, think what kind of impression will be remained in your mind :). So it’s worthwhile if you can reload only the part in the web page which contains the large photo. To help you in this kind of situation, the technology called AJAX come to the stage.

These requirements can also archive by using Flash or Java Applet. But to view Flash .SWF file you want Flash player installed in your computer and to run Java Applet you need JRE in your machine. But to use AJAX, you want only JavaScript enabled browser and most of today browsers have JavaScript.

Remind that, if you have a desire of coding, and you want your visitors to have better user experience with your website, then AJAX should be there on your web site.

Posted in Technology, Uncategorized | Tagged: , , , | Leave a Comment »