1
在以下腳本中加載外部json文件的最佳方式是什麼?從外部文件加載json
function loadimages(id, data, path) {
var x = data.imagefeed;
var output = ""; // initialize it outside the loop
$.each(x,function()
{
output += '<li><img src= "'+path+''+this.images+'" alt ="'+this.name+'"></li>';
});
$(id).append(output);
}
mydata.json
var info = {
"imagefeed": [{
"name": "rest1",
"images": "image1.png"
}, {
"name": "rest2",
"images": "image2.png"
}]
};
定義外部?服務器?你打算如何發送它。 – Liam
你的JSON文件實際上是JavaScript。最後刪除'var info ='和';' –