Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

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.