1 | initial version |
Here are the steps to store data in a data attribute and utilize it through Ajax:
<div class="product" data-product-id="123">Product details</div>
data()
or attr()
method as follows:var productId = $(".product").data("product-id");
123
, you can make an Ajax call as follows:$.ajax({
url: "product-details.php",
data: { id: productId },
success: function(result) {
// handle result
}
});
In this example, the data
property is used to pass the productId
variable to the server-side PHP script. The result
parameter in the success function contains the data retrieved from the server.