jquery - 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);
}
});
回复告诉我金额缺失。
解决方案
你可以尝试这样的事情:
var postData = {
product: {
153: 1
}
};
推荐阅读
- html - 有没有办法将数据从在客户端成像
- postman - Postman:有没有办法用 ESLint 检查 Pre-request Scripts 和 Tests?
- python - 如何迭代页面以抓取网络新闻
- azure-ad-b2c - MSAL js-acquireTokenSilent 失败并出现 X-Frame-Error
- awk - 按一列分组,根据该列查找最小值和最大值并计算滑动窗口 awk 的平均值
- angular - 未从 Angular 中的服务接收变量值
- python - openpyxl 将行追加到列表,然后将列表复制到新工作表
- python - 获取相关性的降序键列表
- ios - 带有来自两个数组的单元格的 uitableview 部分
- r - 我应该将我的虚拟变量转换为因子吗?