seikan / Cart

A simple PHP shopping cart class to use in ecommerce web applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Post without refreshing

rasselll opened this issue · comments

hey any chance you can provide me an example of this working through using a database for the data?

Can you show me some example codes so I can assist you further?

Hey thanks, i actually would now would like to post the data or attributes to 'add' without refreshing the page,. So at the moment it is able to hold the data in the array, but still need press refresh to see that data. I would like to increase the cart count without having to press refresh.

example.php

	// Add item
	if (isset($_POST['add'])) {
		foreach ($products as $product) {
			if ($_POST['id'] == $product->id) {
				break;
			}
		}

		$cart->add($product->id, $_POST['qty'], [
			'price' => $product->price,
			'color' => (isset($_POST['color'])) ? $_POST['color'] : '',
			'size' => (isset($_POST['size'])) ? $_POST['size'] : '',
		]);

	}



here is the code I have so far to post to 'add' without refreshing but not sure if its correct. For now when i click the button '.add-to-cartnon' it seems to add the attribute data to 'add' but i dont see it until i hit refresh. so again i would like to update the cart count without having to press refresh

					$('.add-to-cartnon').on('click', function(){
			
					var $btn = $(this);
					var id = $btn.parent().parent().find('.product-id').val();
					var color = $btn.parent().parent().find('.color').val() || '';
					var qty = $btn.parent().parent().find('.quantity').val();
					var size = $btn.parent().parent().find('.size').val() || '';
                                        var add= $btn.parent().parent().find('.add').val() || '';

						$.ajax ({
							method: 'post',
							url: 'example.php',
							data: {
							
								id: id,
								color: color,
								qty: qty,
								size:size,
								add:add

							},
							success: function(data) {
						
			
										}
						});
					});

It seems like this is Javascript problem. I believed you need to do something at your AJAX success callback.

You need to rewrite the content back to your cart.