我一生都无法弄清楚如何访问该对象中的值。任何帮助将不胜感激
最终目标,一旦我可以访问链接,我将在 images-header 元素之后迭代每个并将 img 标签附加到 dom 中。
JS消费json
$("#stack_name").focusout(function() {
var name = $(this).val();
// alert(name);
$.getJSON('/images.json?name='+ name, function(data) {
console.log("DATA: ", data);
// $('<p>Test</p>').appendTo('.images-header');
});
});
控制台日志输出:
DATA:
Object {data: Object}
data: Object
images: Array[4]
0: "http://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Connecticut_in_United_States.svg/270px-Connecticut_in_United_States.svg.png"
1: "http://www.enchantedlearning.com/usa/states/connecticut/map.GIF"
2: "https://familysearch.org/learn/wiki/en/images/0/01/Connecticut-county-map.gif"
3: "http://www.ct.gov/ecd/lib/ecd/20/14/state%2520of%2520connecticut%2520county%2520outline.jpg"
length: 4
__proto__: Array[0]
__proto__: Object
__proto__: Object
app-init.js?body=1:15
/images.json?name=connecticut
{
"data": {
"images": [
"http://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Connecticut_in_United_States.svg/270px-Connecticut_in_United_States.svg.png",
"http://www.enchantedlearning.com/usa/states/connecticut/map.GIF",
"https://familysearch.org/learn/wiki/en/images/0/01/Connecticut-county-map.gif",
"http://www.ct.gov/ecd/lib/ecd/20/14/state%2520of%2520connecticut%2520county%2520outline.jpg"
]
}
}