1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

Modular JavaScript Library

Ajax Library

This particular addition to my modular library of JavaScript routines is a little less developed than the others as the $A object currently has no properties or methods associated with it apart from the method to process the response that is returned that you code yourself and add using the second parameter when you create a $A object in the first place.

You create a $A ajax object using the following code:

var myAjax = new $A(url,process,'POST',formid);

As you can see there are four parameters, two of which are optional. The first parameter contains the address on the server that is being accessed to process the ajax request. For a GET request this will have a querystring on the end supplying all of the values being passed to the server for your lookup request.

The second parameter is the name of a function that you are adding to the object as the method that will process the response from the server. Here's a template for what this function should look like:

process = function() {
if (this.readyState == 4) {
if (this.status != 200) {
alert('Error : Status '+this.status+' returned.');
} else {
var cType = this.getResponseHeader("Content-Type");
if (cType == 'text/xml') {
} else if (cType == 'text/plain') {
document.getElementById('fld3').value = this.responseText;
} else {
alert('unknown content type');

You will need to substitute your actual processing for after the response is returned for the various alerts.

The third parameter can be either 'GET' if you are doing a lookup and passing a querystring on the end of the first parameter or 'POST' if you are doing an update. If the parameter is omitted then 'GET' will be assumed. Where 'POST' is specified a reference to the form containing the fields to be sent needs to be specified as the fourth parameter (eg. document.getElementById('fld').form if 'fld' is an id on a field within the form).

To get a copy of this object to use in your scripts simply copy the following JavaScript and insert it in your page were needed.

You are welcome to make modifications to the $A definition for use on your site provided that you post a copy of your amendment to my what's missing page to share your idea with everyone.

See More About

©2016 About.com. All rights reserved.