我搜索了FOREVER,无法对我的问题做出明确的答案.所以这就是.我有一个JSON文件(我去jsonlint验证,它说它很好)看起来像这样(一些信息修改):
[{
"position":"1",
"category":"A",
"title":"Title to first story",
"description":"The first story."
},
{
"position":"2",
"category":"B",
"title":"Title to second story",
"description":"The second story"
},
{
"position":"3",
"category":"B",
"title":"Title to third story",
"description":"The third story"
}
]
Run Code Online (Sandbox Code Playgroud)
我使用jQuery解析并使用此函数放置一个html页面:
$.getJSON('page.json', function(data) {
var items = [];
$.each(data.reponse, function(item, i) {
items.push('<li id="' + i.position + '">' + i.title + ' - ' + i.description + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
});
Run Code Online (Sandbox Code Playgroud)
它完美无缺!现在我的问题是,JSON文件不会在本地托管,实际上将托管在一个单独的域上.所以我修改了我的代码如下(经过一些阅读)希望让它工作:
$.getJSON('http://www.otherdomain.com/page.json?format=json&callback=?', function(data) {
var items = []; …Run Code Online (Sandbox Code Playgroud)