How to send data to add to the cart page in Shopify using Ajax?

To send data using Ajax in Shopify at add to cart page we need a simple Ajax code which has been given below. Use the code and change it according to requirement.
$.ajax({
type: 'POST',
url: '/cart/add.js',
data: {
  quantity: 1,
  
  id: "paste your varient id here",
  properties: {
"name":"xyz",
"address":"abc",
"city":"city name"
}
  

},
  dataType: 'json', 
 success: function (data) { 
   alert("Success");
  
 
 },
 error: function (request, status, error) {
   alert("error ");
  
} 
 });

How to send data to add to the cart page in Shopify using Ajax?expoundsofttechsolution

ghb