midoriAjax
Ajax is a technology that allows web applications to retrieve data from the server in the background without having to reload the page.
-
midoriAjax(callback, params, cache)Creates an Ajax object.
callback is the callback function that will be called when a response comes back from the server. If you do not want to process the server response, you can simply pass an empty function like this: function () {}.
params is optional. When present, it will be passed to the callback function.
cache defaults to false. When set to true, the server will not be queried for the same requests over and over again, and the cached responses will be passed to the callback function instead.
Example:// Checks if the username is valid when the form is submitted var usernameCheck = new midoriAjax(function () { if (usernameCheck.responseText == 'OK') midori.get('#message-form').submit(); }, '', true ); midori.addEventListener( midori.get('#message-form'), 'submit', function (e) { usernameCheck.post('/index.php', 'do=check&username=' + midori.get('#username').value); } ); -
post(where, what, verb, headers)Posts an Ajax request.
where is the path of the file on the server that will be called.
what contains the parameters that will be passed to the file.
verb is optional. If omitted, it is assumed to be 'POST'.
headers is optional. An array containing HTTP headers.
Example:// Updates page counter var counter = new midoriAjax(function () { midori.get('#my-div').innerHTML = counter.responseText; } ); midori.addEventListener(window, 'ready', function (e) { counter.post('/site_counter.php', ''); } );
