AJAX Made Simple
midori makes it easy to make AJAX requests. It's a two-step process:
- Create an AJAX object by passing it a callback function.
- Make an AJAX call to the server.
In the following example, we will update a counter on our page by querying the server. We first create an AJAX object and pass it to our callback function.
var counter = new midoriAjax(function () {
midori.get('#my-div').innerHTML = counter.responseText;
} );
The callback function simply updates the contents of a div element with the id my-div by using the AJAX object's responseText property.
We make our AJAX call as soon as the page is ready. We just call a server-side script called site_counter.php. Once this script returns a response, the callback function we defined earlier will be called.
midori.addEventListener(window, 'ready', function (e) {
counter.post('/site_counter.php', '');
} );
Fore more information, you can refer to documentation entry for midoriAjax.
