[英]getJSON doesn't work
對象.js
var data = [ {
image: 'gallery/objecten/bear.jpg',
thumb: 'gallery/objecten/bear.jpg',
title: 'my first image',
description: 'Lorem ipsum caption',
link: 'http://example.com'
}
];
在我的主 js 文件中,我正在執行以下操作:
$.getJSON("gallery/objecten/objecten.js",function(data) {
$.each(data, function(key, value) {
alert("hello?");
});
});
警報不起作用,那是怎么回事?
您的 json 格式不正確。 盡管有格式,但您不應該有var
聲明。 它應該是:
對象.js
[{
"image":"gallery/objecten/bear.jpg",
"thumb": "gallery/objecten/bear.jpg",
"title": "my first image",
"description": "Lorem ipsum caption",
"link": "http://domain.com"
}]
注意 json 中的字符串和屬性名稱必須用"
要了解有關 json “格式”及其編碼規則的更多信息,請參閱http://json.org
希望這可以幫助。 干杯
object.js 不包含 json
[{
"image": "gallery/objecten/bear.jpg",
"thumb": "gallery/objecten/bear.jpg",
"title": "my first image",
"description": "Lorem ipsum caption",
"link": "http://domain.com"
}]
已編輯 - 我刪除了包裹它的括號,不知道為什么我把它們放進去現在工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.