A
A
alestro2015-12-17 11:36:35
PHP
alestro, 2015-12-17 11:36:35

How to refresh part of a page?

There is a certain online store, it has products that can be added to the cart. So I screwed the add ajax button to the button and when you click the data, via post, they fly to the server, where it writes them to the basket session. But I want the cart to be updated without reloading the page. I know that json should be used here. But how exactly to implement - I do not understand. Even figure out the sequence of actions.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
IceJOKER, 2015-12-17
@IceJOKER

The easiest way is to issue a cart code on some request and simply replace the old cart with a new one.

$.get('/get-cart.html', function(data){

 $('.my-cart').replaceWith(data); 

});

And the variant with json - after adding a product, you get a list of products in json format and add products in a loop

A
Alexander Wolf, 2015-12-17
@mannaro

If you don't want to get too deep, then

$('#cart-block').load(location.href + ' #cart-block', function() { $(this).children().eq(0).unwrap() });

Where cart is the html ID of the cart.

V
Vladislav, 2015-12-17
@MrBikus

The script that sends the ajax request must receive the result from the server and change the html. The server, in turn, receives an ajax request and returns a result, for example, in json format, on the basis of which html changes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question