Page 2 of 2

Re: How do I create an Ajax Listener, so content changes dyn

Posted: Wed Dec 09, 2015 11:18 am
by Celauran
simonmlewis wrote:I take it the "URL" part is the path to the PHP file that runs all the database query code?
Yes
simonmlewis wrote:What is the "item_id: item, quantity: qty"?
The item and quantity of said item being added to the cart. Just a pseudo-code example, though. These would be the inputs being passed to your PHP functions.
simonmlewis wrote:How is that taking information from the query, as I think I see that then going into the next success: part of the function.
You're sending a request to a URL. Whatever response is returned from that request is what gets passed to the success callback. In the discussion above, you were returning the new number of items in the cart, which is what I mocked up. In practice, it could be anything.

Re: How do I create an Ajax Listener, so content changes dyn

Posted: Wed Dec 09, 2015 12:23 pm
by Christopher
One concept you may be missing is using JSON. I have PHP convert all the data I send to Javascript to JSON. It can then be either embedded into the page when the page is generated, or sent back from an Ajax call. Then within Javascript you are just dealing with an object or array because JSON is essentially code. From that point it should be easy for you to update the cart display.