首页 > 解决方案 > Jquery Ajax 使用 POST 将数据发送到端点

问题描述

我需要将 som 数据发送到端点。在文档中,它被写为 product[xx][amount],其中 xx 是一个 id。我无法弄清楚语法应该是什么。

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

或者

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

也许。但它们都不起作用。

整个代码是

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);
            }
          });

回复告诉我金额缺失。

标签: jqueryajax

解决方案


你可以尝试这样的事情:

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

推荐阅读