O'Reilly logo

PHP Ajax Cookbook by R. Rajesh Jeba Anbiah, Roshan Bhattarai, Milan Sedliak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Ajax shopping cart

Shopping carts play an important role in e-commerce websites. In this task, we will learn how to build a shopping cart with Ajax functionality to provide the best user experience. The result of this task will look like the following screenshot:

Ajax shopping cart

Getting ready

All we need for this task is the latest jQuery library and a sample .php file, ajax/shopping-cart.php.

This script will provide basic server functionality to retrieve and receive data:

<?php if($_POST["productID"] && $_POST["action"]){ $productID = $_POST["productID"]; $action = $_POST["action"]; switch($action){ default: $result["status"] = "ERROR"; $result["message"] = "Product ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required