gpt4 book ai didi

javascript - 未找到 JSON key

转载 作者:行者123 更新时间:2023-12-02 18:36:49 26 4
gpt4 key购买 nike

我的问题是我必须以以下格式发布 JSON 对象:

{ "key1": "value1",
"key2": 2,
"options": {
"content": "lorem ipsum"
}
}

但我不断收到内部服务器错误:未找到关键“选项”。这是我的 js 代码:

$("#button").click(function(){
var json_test = {
"key1": "value1",
"key2": 2,
"options": {
"content": "lorem ipsum"
}
}
$.ajax
({
type: "POST",
url: '/test/url/',
dataType: 'json',
data:json_test
})
});

这也是 Firebug 的 POST 内容:

element_type    Text
learning_page 1
options[content] lorem ipsum

我显然做错了什么,但我就是不知道它是什么。有什么想法吗?

最佳答案

我不确定,但你可能缺少字符串化 json

$("#button").click(function(){
var json_test = {
"key1": "value1",
"key2": 2,
"options": {
"content": "lorem ipsum"
}
}
$.ajax
({
type: "POST",
url: '/courses/api/elements/',
dataType: 'json',
data:JSON.stringify(json_test)
})
});

另外尝试添加

contentType: "application/json; charset=utf-8"

到你的jquery选项

关于javascript - 未找到 JSON key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17243624/

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