gpt4 book ai didi

jquery - 无法获取 Json

转载 作者:行者123 更新时间:2023-12-01 08:24:09 24 4
gpt4 key购买 nike

我想获取一个 json 以仅在 div 中显示 syn。

就像:--

$.getJSON('http://words.bighugelabs.com/api/2/eba286cdc7f3619674544d80ce94cb1b/stack/json', function(data) {

//parse the response to display in a div


});

output format.

<小时/>

来自链接的 JSON 标记:

{
"noun": {
"syn": [
"batch",
"deal",
"flock",
"good deal",
"great deal",
"hatful",
"heap",
"lot",
"mass",
"mess",
"mickle",
"mint",
"muckle",
"peck",
"pile",
"plenty",
"pot",
"quite a little",
"raft",
"sight",
"slew",
"spate",
"tidy sum",
"wad",
"push-down list",
"push-down stack",
"smokestack",
"push-down storage",
"push-down store",
"agglomerate",
"chimney",
"cumulation",
"cumulus",
"large indefinite amount",
"large indefinite quantity",
"list",
"listing",
"memory device",
"mound",
"storage device",
"whole lot",
"whole slew"
]
},
"verb": {
"syn": [
"pile",
"heap",
"arrange",
"lade",
"laden",
"load",
"load up",
"set up"
],
"rel": [
"heap up",
"pile up",
"stack away",
"stack up"
]
}
}

最佳答案

由于同源策略,JSON 无法加载,只需将 ?callback=? 附加到您的世界即可。更新后的代码,

$.getJSON('http://words.bighugelabs.com/api/2/eba286cdc7f3619674544d80ce94cb1b/stack/json?callback=?', function(data) {
//parse the response to display in a div
//you can access the JSON object from the data object.
});

更新:

当您将 ?callback=? 附加到 $.getJSON 中使用的 URL 时,jQuery 会理解这是一个 JSONP 请求,而不是用于获取 JSON 的 XMLHttpRequest。实际上回调参数可以是任何东西,但值必须是 ? 才能触发 JSONP 请求。

发出请求时,jQuery 将参数替换为 ?callback=jQuery15107307685413397849_1299439987443,每次发出请求时该值都是唯一的。

关于jquery - 无法获取 Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5211378/

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