When you click on the .btn class, you need to add a test block to the .container with values from the JS object, and then somehow send this data to the database for further processing.
Unfortunately, I do not know where to start. I understood only one thing: I need to send an ajax request to something like this:
$.ajax({ url: "test.php", type: "post", dataType: "json", data: { } Object to shove in JSON. But where to push this AJAX code, how to associate with the variable water, what to write in PHP code is no idea.
I would be grateful for any help - links, maybe some other solutions.
var water = { name: 'water', count: 200 }; $('.btn').on('click', function() { $('.container').append( `<div class='test'>\n<div class='test__name'>${water.name}</div>\n<div class='test__price'>${water.count}</div>\n</div>` ); }); .btn { width: 100px; height: 100px; background-color: red; } .container { background-color: #2a66ad; } .test { color: #000; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="btn"> </div> <div class="container"> <div class="test"> <div class="test__name"> </div> <div class="test__price"> </div> </div> </div>
water.namewater.count? - qwabra