Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Ajax shooping cart

Hi there, hope someone could guide me the steps in what im trying to acomplish, im creating a shooping cart in php, but i liked to enhance the aplication, for example i liked to add products in same page without the browser refreshing, my only question is how can i save data from a product in javascript to later to get and use this data to checkout?

1 Answer

Each product would be an object and you would store each product the user has added into an array (in JSON format). So if you have an add product button on each product, the chosen product would be pushed to an array and then asynchronously posted to the server where your PHP code can parse it out and store it in a database.

At the same time, the user's shopping cart is using AJAX to read that JSON file and show the user what he currently has on his shopping cart.