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

标签 javascript jquery object get

我从 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/

相关文章:

javascript - 如何将对象从 View 传递到 Controller

javascript - 阻止重新加载页面的链接

java - JTable 将行值存储为对象

javascript - 在 Javascript 中查找模式

javascript - WordPress 插件如何处理表单提交

javascript - 添加特定类型的对象时如何更改 "mode"?

javascript - Safari 中的 html2canvas 不在 SVG 路径上呈现 Javascript style.fill

javascript - ASP.NET 中的条件 Javascript 正则表达式验证

javascript - 使用ajax接收php中序列化的数据

c++ - 如何正确创建一个包含由不同类的实例组成的 union 的类?