Toolkit
Ajax
This object is included in the minified toolkit library and is required for all the Ajax methods used. It acts as a helper for all ajax requests.
Simple Ajax GET
{
_: "button",
innerHTML: "Test",
onclick: function() {
Ajax.do("ExampleData.txt", null, function(response) {
alert(response);
});
}
}
Reference
The following functions can be used:
- Ajax.do(get, post, callBack, callBackData, extraSettings);
- Ajax.doAjaxToDiv(get, post, divName, extraSettings);
- Ajax.doAjaxToDivElement(get, post, divElement, extraSettings);
- Ajax.doAjaxFormSubmit(formElement, callBack, submitButton, extraSettings);
- Ajax.doAjaxFormSubmitToDiv(formElement, divName, submitButton, extraSettings);
- Ajax.clearSaved();
- Ajax.clearCached();
Optional: post parameter, if null or undefined is passed the request will be executed as GET request.
Optional: callBackData, this information will be passed to the callback method as second parameter.
Optional: submitButton, If included, this value will also be passed, just like a normal form.
Optional: extraSettings parameter, it can be passed as an { } object and can contain these settings:
- timeout (int, default 30000) - automatically end and retry the request after x milliseconds.
- saveResults (boolean, default false) - save this url and response to the browsers localStorage (kept after page refresh). This saved version will only be used when a request to this url in the future fails.
- cacheResults (boolean, default false) - save this url and response to a javascript variable (lost after page refresh).
- executeScriptTags (boolean, default true) - parse the response and execute all script tags.
- allowEmptyResponse (boolean, default false) - If set to false, empty requests will be seen as error and cause a retry (This can happen in Internet Explorer in some cases).
- showServerErrors (boolean, default true) - Show alert message with error if the HTTP result code is 400 or higher.
- maxRetries (int, default 3) - Max number of retries if the request fails.
- parseJSONResponse (boolean, default false unless object is posted) - Parse the JSON response before passing it to the callback
Note that defaults kan be overwritten by directly setting the parameter on the Ajax object (for example: Ajax.timeout = 60000; ).
The extraSettings can also be set on the TK. components which are using ajax using the property AjaxSettings.