DOMAssistantAJAX Module

The DOMAssistantAJAX module offers basic AJAX interaction for retrieving data from a URL and then passing on the returned content to any function, or load the content into an element.

get(url, callBack)

Makes a GET request to the specified URL and calls the set callBack function. The first parameter of the then called callBack function will be the responseText of the AJAX call. If this method is called on an element, the callBack function context will be the element, i.e. the keyword this will refer to the element which called the get method in the first place.

Parameters

url
URL to make an AJAX call to. Required.
callBack
Function name or anonymous function to call when the AJAX request is complete. Optional.

Return value

Element which called the method.

Example calls

$("news").get("news.php", insertNews);

DOMAssistant.AJAX.get("my-url.aspx", callbackFunctionName);

post(url, callBack)

Makes a POST request to the specified URL and calls the set callBack function. The first parameter of the then called callBack function will be the responseText of the AJAX call. If this method is called on an element, the callBack function context will be the element, i.e. the keyword this will refer to the element which called the post method in the first place.

Parameters

url
URL to make an AJAX call to. Required.
callBack
Function name or anonymous function to call when the AJAX request is complete. Optional.

Return value

Element which called the method.

Example calls

$("news").post("news.php?value=true", insertNews);

DOMAssistant.AJAX.post("my-url.aspx?number=10", callbackFunctionName);

load(url, add)

Makes a request to the specified URL and loads the returned content into the element which the method is called on.

Parameters

url
URL to make an AJAX call to. Required.
add
A boolean, if the retrieved content shall be appended to the already existing content, as opposed to replacing it. Optional.

Return value

Element which called the method.

Example calls

$("directions").load("maps.php");

$("contacts").load("staff.aspx", true);

ajax(option)

A general-purpose method of doing more advanced AJAX calls where parameters are set manually.

Parameters

option
A JavaScript object with different parameters set. Available parameters are: url, method, params, callback, headers, responseType, timeout, exception. Required.

Return value

Element which called the method.

Example calls

$("#container").ajax({
	url : "ajax.php",
	method : "POST",
	params : "name=DOMAssistant",
	callback : functionReference,
	headers : {
		"Content-type" : "application/x-www-form-urlencoded"
	},
	responseType : "json",
	timeout : 5000,
	exception : function(e) {
		alert("Ajax error: " + (e.message || e.description));
	}
});

getReadyState()

Helper method to check the current readyState of the XMLHttpRequest.

Parameters

None

Return value

Integer.

  • 0 = uninitialized
  • 1 = loading
  • 2 = loaded
  • 3 = interactive
  • 4 = complete

Example calls

DOMAssistant.AJAX.getReadyState();

getStatus()

Helper method to check the current status of the XMLHttpRequest.

Parameters

None

Return value

Integer. Examples are 200 for Ok and 404 for not found.

Example calls

DOMAssistant.AJAX.getStatus();

getStatusText()

Helper method to check the current status text of the XMLHttpRequest.

Parameters

None

Return value

String. The text accompanying the status code.

Example calls

DOMAssistant.AJAX.getStatusText();

Get your copy