【发布时间】:2017-09-05 20:52:10
【问题描述】:
我正在练习 Ajax 调用,但在访问返回的 JSON 数据时遇到问题。
我有下面的代码
$('button').on('click', function() {
$.ajax({
url: 'http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1',
success: function(data) {
console.log(data);
},
error: function() {
console.log('error occured');
},
cache: false
});
});
哪个输出
[
{
"ID": 1127,
"title": "Paul Rand",
"content": "<p>Good ideas rarely come in bunches. The designer who voluntarily presents his client with a batch of layouts does so not out prolificacy, but out of uncertainty or fear. </p>\n",
"link": "https://quotesondesign.com/paul-rand-7/"
}
]
我只是想输出我的 JSON 对象的 content 和 link 属性。我尝试了以下方法:
$('.message').html(JSON.stringify(data));
哪个输出
[{"ID":2294,"title":"Josh Collinsworth","content":"
You do not need to have a great idea before you can begin working; you need to begin working before you can have a great idea.
\n","link":"https://quotesondesign.com/josh-collinsworth-3/"}]
我正在寻找操作 JSON 数据的标准方法,感谢所有帮助!
【问题讨论】:
标签: javascript jquery json ajax