Understanding the Non-Ajax Version
The first thing you’ll need to do is make sure you have a proper non-Ajax version of the tasks at hand. There are two reasons for doing so:
- First, it gives you, the developer, the chance to create the entire, fully functioning system without the confusion of Ajax (Ajax can make debugging harder).
In either case, the user shouldn’t know that the alternative approach even existed.
Rather than come up with a new example, I’ve decided to build off of the second e-commerce project from my book (see the earlier link). You can view the site in a demo mode (without the modifications discussed in this article). If you have an existing e-commerce site, you can probably use it as your basis for Ajax expansion per the instructions to follow.
The non-Ajax version of the shopping cart on that site uses one scriptcart.phpfor all things related to the shopping cart. To add a new product to the cart, the script needs to receive a SKU and an action value in the URL:
Any page that allows for an item to be added to the shopping cart, such as one that displays a product or lists sale items, just creates a link like that.
Once you have all this working for your e-commerce site, you can “Ajax-ify” it.