Tuesday, October 21, 2008

Weekly Source Code: My AJAX Library

Back when AJAX first came out there wasn't any libraries - no ASP.Net AJAX etc. I was mainly doing classic ASP with VBScript development (yes I know - that sucks!)

Most AJAX books and samples demonstrated using the XMLHttpRequest object are for making AJAX calls but the main problem was compatibility between the different web browsers - IE vs Firefox vs Safari vs Opera.

So I wrote my own AJAX library, I mainly used it for validation and later to pull customer information into a HTML form if the customer already placed an order.

To use it:

Setup 1: Include the JavaScript file into your HTML page.

Setup 2: Call AjaxValidate function, this function has 3 parameters:
  • psWebPage: The back-end server side page to call.
  • psCode: Code that identifies the request, if you send more than one request to a back-end server side pagethen this can be used to identify the request so that the page handles different request. You can leave this blank if your page handles only 1 request.
  • psValue: The request value.
Setup 3: When the result comes back it will call the setOutput JavaScript function that has 3 parameters:
  • sWebPage: The back-end server side page that was called.
  • sCode: The code sent to AjaxValidate function your JavaScript can process the request.
  • sResponseText: The response from the AJAX call. This can be HTML, plain text or even JSON.
With the AJAX frameworks of today my library don't have much of a meaning since you can do alot of advance AJAX functionality.

More about AJAX in the next Weekly Source Code.

No comments: