GithubHelp home page GithubHelp logo

Post without refreshing about cart HOT 3 CLOSED

rasselll avatar rasselll commented on August 15, 2024
Post without refreshing

from cart.

Comments (3)

seikan avatar seikan commented on August 15, 2024

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

from cart.

rasselll avatar rasselll commented on August 15, 2024

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) {
						
			
										}
						});
					});

from cart.

seikan avatar seikan commented on August 15, 2024

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.

from cart.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.