readyState == 4)
{
// Continue only if HTTP status is "OK"
if (xmlHttp.status == 200)
{
try
{
// Read the response
response = xmlHttp.responseText;
// Server error?
if (response.indexOf("ERRNO") >= 0 || response.indexOf("error") >= 0)
{
handleError(response);
}
CHAPTER 13 ?– IMPLEMENTING AJAX FEATURES 428
else
{
// Update the cart
document.getElementById("contents").innerHTML = response;
// Hide the "Updating..." message
document.getElementById('updating').style.visibility = 'hidden';
}
}
catch (e)
{
// Handle error
handleError(e.toString());
}
}
else
{
// Handle error
handleError(xmlHttp.statusText);
}
}
}
3. Change index.php as highlighted:
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
{
$application->display('cart_details.tpl');
}
}
else
trigger_error('CartAction not set', E_USER_ERROR);
4. Load your shopping cart, and ensure it works as expected.
CHAPTER 13 ?– IMPLEMENTING AJAX FEATURES 429
How It Works: The AJAX Shopping Cart
Because you wrote the code AJAX code earlier in this chapter, the task in this exercise was fairly easy. To upgrade
the shopping cart, you needed to follow three easy steps.
First you modified the shopping cart template (cart_details.
Pages:
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544