3
var mydata = {
    "one": {
        "brand": "acer",
        "cost": "212132"
    }
}


$.ajax({
        url: 'http://localhost',
        type: 'post',
        dataType: 'json',
        data: JSON.stringify(mydata)
    });

Above code is adding a colon to the data when i view the form send data in chrome dev tools. Is there anything wrong with the request?

4

2 回答 2

8

您正在查看 application/x-www-form-urlencoded 解析数据。所以 Chrome 正在尝试建立键值对。单击网络选项卡视图中“表单数据”标题附近的“查看源代码”。您将看到没有冒号的 JSON。

于 2015-09-25T13:50:06.750 回答
2

对我来说也是一样。查看源代码时我没有看到冒号。但它没有用。我的解决方案是添加缺少的contentType

$.ajax({
        url: `url`,
        contentType: "application/json",
        type: "POST",
        data: JSON.stringify(data)
  });
于 2019-08-29T12:30:01.413 回答