Wednesday, September 17, 2008

Simple Ajax Functions - Snippets

Basic Ajax Functions
I’ve created a list of very common JavaScript functions for Ajax. They have been created in quick reference fashion and do not contain any fancy stuff. Instead of creating one function which can handle various tasks depending on passed values, they are split into seperate basic task functions. The reason for this is simplicity.

Anyway - here they are. I’ll post the function and give a basic outline of what it does.

This first function is the real important one - it’s the one which creates the object for making the Ajax connection.

Here is the function which sends the request to the server script. This version creats the connection with TEXT and uses the POST method.

Here is the function which sends the request to the server script. This version creats the connection with TEXT and uses the GET method.

Here is the function which sends the request to the server script. This version creats the connection with XML and uses the POST method.

Here is the function which sends the request to the server script. This version creats the connection with XML and uses the GET method.

Now here is the function which retrieves the response from the server script. This version receives the response as TEXT (http.responseText).

Now here is the function which retrieves the response from the server script. This version receives the response as XML (http.responseXML).

This little function can be used to delay the call - handy for forms where you use onKeyUp or onKeyPress to trigger submit action.

Readmore.............
From : http://www.ajaxtutorial.net/index.php/2006/03/08/simple-ajax-functions-snippets/

No comments: