Instead, we try to execute the action requested by the visitor
in a non-AJAX fashion. Here we use actionObject, which represents the form submitted by the visitor or the
action link clicked by the visitor. If actionObject isn??™t set, it means the error happened in the JavaScript function
referenced in the onclick or onsubmit attribute. In that case, we simply need to return true, which causes the
original requested action to happen:
// Fall back to non-AJAX behavior
else if (!actionObject.tagName)
{
return true;
}
If actionObject is a link, it means the error happened after the visitor clicked a link, in which case we redirect
the request to that URL:
// Fall back to non-AJAX behavior by following the link
else if (actionObject.tagName == 'A')
CHAPTER 13 ?– IMPLEMENTING AJAX FEATURES 422
{
window.location = actionObject.href;
}
If actionObject is a form, it means the error happened after the visitor submitted a form, in which case we redirect
the request to that URL:
// Fall back to non-AJAX behavior by submitting the form
else if (actionObject.tagName == 'FORM')
{
actionObject.submit();
}
}
The index.php script was updated to respond to AJAX requests as well. When making an asynchronous request
to index.php, the AjaxRequest parameter is added to the query string so that index.php knows to react
accordingly. First it sets the appropriate header values to make sure the response isn??™t cached:
if (isset ($_GET['AjaxRequest']))
{
// Headers are sent to prevent browsers from caching
header('Expires: Fri, 25 Dec 1980 00:00:00 GMT'); // Time in the past
header('Last-Modified: ' .
Pages:
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538