It’s about programming

October 7, 2008

AJAX says “Hello World”

Filed under: .NET, Web Development — Lakmal @ 2:34 pm

AJAX is an new technique and not an new programming language. Basically it is using XMLHttpRequest Object to deal web server.

XMLHttpRequest

XMLHttpRequest is a JavaScript object that was created by Microsoft and adopted by Mozilla. You can use it to easily retrieve data via HTTP. Despite its name, it can be used for more than just XML documents.

First step of Implementing Simple AJAX application is to initiate XMlHttpRequest Object. Different Browsers are supporting deferent scenarios to create XMLHttpRequest Object. In internet Explore it’s using ActiveXObject while other browsers used built in JavaScript Object called “XMLHttpRequest”

This code snippet is fixed for all AJAX implementation and it will provide XMLHttpRequest object.

And the second step is to initiating “onreadystatechange” property of XMLHttpRequest object. It’s about how you handle response from the server for the Request which we are sending through XMLHttpRequest object.

This property is simply function pointer and it should be assign Function which we handle Server Response.

In the mean time of Server Request processing, XMLHttpRequest object will having five different states. And those are explaining object current Request processing state.

0 The request is not initialized
1 The request has been set up
2 The request has been sent
3 The request is in process
4 The request is complete

And state 4 is the request processing complete state and that why I have checked it within the function. If state is 4, response text is written to HTML document controller property.

And the third step is to open request object and send to the server.

“open” method accept three argument and those are accordingly Request Sending Method, URL of server side script and third one is whether request is going to process Asynchronously.

In addition to this we need to write server side script to say “Hello World” to the Response of Client Request.

In my case it’s an ASP.NET back end and it doesn’t matter which language you used in server side implementation. What you need to do is just write “Hello World” to Server response back to Client browser.

Hey, I’m happy I got the right response without much effort.

Regards

Lakmal

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.