gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/html');
Then the existing code that adds a new product to the cart is used to perform the requested action. The
cart_summary.tpl template is sent to the output, and the JavaScript will use it to update the cart summary
box using the JavaScript DOM functions:
if (isset ($_GET['CartAction']))
{
$cart_action = $_GET['CartAction'];
if ($cart_action == ADD_PRODUCT)
{
require_once PRESENTATION_DIR . 'cart_details.php';
$cart_details = new CartDetails();
$cart_details->init();
$application->display('cart_summary.tpl');
}
}
else
trigger_error('CartAction not set', E_USER_ERROR);
}
The updateCartSummary() JavaScript function in ajax.js is responsible for reading the HTML code generated
by cart_summary.tpl and injecting it into the cart summary box. The function first verifies that the request
CHAPTER 13 ?– IMPLEMENTING AJAX FEATURES 423
has not resulted in an error, in which case the handleError() function is called to either display the error or fall
back to non-AJAX behavior:
// Process server's response
function updateCartSummary()
{
// Read the response
response = xmlHttp.responseText;
// Server error?
if (response.indexOf("ERRNO") >= 0 || response.indexOf("error") >= 0)
{
handleError(response);
}
If the response doesn??™t contain an error, it??™s assumed to contain the HTML contents of the new cart summary box.
Pages:
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539