Jquery Ajax Send data to endpoint with POST

Viewed 116

I need to send som data to an endpoint. In the documentation it is written as product[xx][amount] where xx is an id. I can't figure out what the syntax should be.

var postData = {
            product:153,
            amount:1
          };

or

var postData = {
            product[153][1]
          };

maybe. But none of them works.

The entire code is

var postData = {
            product:153,
            amount:1
          };

          $.ajax({
            url: '/actions/cart/add',
            type: 'POST',
            dataType: 'text',
            contentType: 'application/json',
            data: postData,
            success: function(data) {
              console.log('Data has been posted');
              console.log(data);
            },
            error: function(err) {
              console.log(err.statusText);
            }
          });

The response tells me that amount is missing.

1 Answers

You can try something like this:

var postData = {
    product: {
        153: 1
    }
};
Related