gpt4 book ai didi

JQuery POST 与 JSON

转载 作者:行者123 更新时间:2023-12-01 04:14:21 25 4
gpt4 key购买 nike

这是我的 json 对象

{
"button": {
"name": "test",
"price_string": "1.23",
"price_currency_iso": "USD",
"custom": "Order123",
"description": "Sample description",
"type": "buy_now",
"style": "custom_large"
}
}

如何在 JQUERY 中编写它?我试图将其写入数据属性内(按原样) - 但它不起作用。

我相信我的问题是语法。

 $.ajax({
url: 'url',
type: 'POST',
data: ____
,"price_string": "1.23"}',
error: function (msg) {
alert( "error" + msg.toString());
},
contentType: 'application/json; charset=utf-8',
dataType: 'json'
});

最佳答案

您需要将对象序列化为 json,如下所示:

var MyObject = {
"button": {
"name": "test",
"price_string": "1.23",
"price_currency_iso": "USD",
"custom": "Order123",
"description": "Sample description",
"type": "buy_now",
"style": "custom_large"
}
};

MyObject = JSON.stringify(MyObject);

$.ajax({
url: 'url',
type: 'POST',
data: MyObject, ...

关于JQuery POST 与 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16246639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com