gpt4 book ai didi

javascript - jQuery 获取无法作为对象访问的数据

转载 作者:行者123 更新时间:2023-11-28 18:14:29 25 4
gpt4 key购买 nike

我从 jQuery GET 请求获得此结果,但它不被视为对象。

[{
"amount": "19323",
"image_tag_id": "1",
"language_iso": "en",
"image_tag": "bla",
"image_content_id": "1",
"image_id": "1",
"last_change": "2010-08-18 09:46:53",
"description": "bla presented by a hairy fly",
"title": "bla_presented_by_a_hairy_fly",
"alt_text": "bla presented by a hairy fly"
}]

这是我得到的结果。我需要在页面上显示金额。但现在,如果我将其作为“imagecount”结果并询问 imagecount.amountimagecount[0].amount,它是未定义的。

echo json_encode($results); //gives the results

$.get('/file.php', imageSearchData, function(imagecount) {
$('.imageAmount').html(imagecount[0].amount);
});

调用文件。

最佳答案

普通的$.get,获取一个json字符串。尝试使用已解析 json 对象的 $.getJSON

 $.getJSON('/file.php', imageSearchData, function(imagecount) {
$('.imageAmount').html(imagecount[0].amount);
});

关于javascript - jQuery 获取无法作为对象访问的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40972084/

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