OK, so this isn't the desired functionality; we don't want to be presenting users
with XML documents. What we want to do now is add some JavaScript to handle
the response.
It's important when we add the JavaScript that we encapsulate it within the window
domready event. This ensures that the JavaScript isn't executed until the DOM
(Document Object Model) is fully loaded:
// add mootools
JHTML::_('behavior.mootools');
$js = "window.addEvent('domready', function()
{
$('form1').addEvent('submit', function(e)
{
// Stop the form from submitting
new Event(e).stop();
// Update the page
this.send({ update: $('update') });
});
});"
Before we add this JavaScript to the page, let's take the time to examine it in
more detail.
The first thing we do is to invoke the mootools JHTML behavior. This ensures that the
mootools library is loaded; without it the JavaScript we want to use will not work.
APIs and Web Services
[ 288 ]
The first line of JavaScript adds a new event handler function to the window
domready event.
Pages:
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395