U
U
user-agent2021-03-27 19:44:46
JavaScript
user-agent, 2021-03-27 19:44:46

How to save changes in the quantity of goods in the cart?

I have a list of items in a shopping cart. When I click on the increase in the number of products, I change the text in the html block with the price of the product * to the number of products and change the text of the Total price block.

After I send a request to get to change the quantity of goods.

$.get('/count_order/', {pk:pk, count:count}).done(function (data) {
       ...
});


The problem is that I click, for example, 10 times on the button to increase the amount of goods and reload. After I see that instead of 11 products I have only 7. That is, one request works faster. I'm sorry for the simple question, I'm new, but I didn't find anything on the Internet. Everyone sends ajax and someone does a setTimeout between requests.
What is the best way to implement dynamic change of products on the site?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antonio Solo, 2021-03-29
@user-agent

before sending the request, block the button and unblock it after receiving the response.
either build a local queue put clicks in it but pull it out and send them strictly in turn, in the second option you can group

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question