我有一个单击按钮,尝试加载json文件。它永远不会达到成功的功能。 我假设我可以在本地加载一个json文件而不必在服务器上加载它? 为什么这不起作用。
$(function(){
$('.demo').click(function(){
$.ajax({
url: 'data/demo.json',
dataType: 'json',
success: function(data){
console.log("data = ", data)
}
});
});
});
这是我的文件夹结构树。
JSON
{"markers": [
{
"point":new GLatLng(40.266044,-74.718479),
"homeTeam":"Lawrence Library",
"awayTeam":"LUGip",
"markerImage":"images/red.png",
"information": "Linux users group meets second Wednesday of each month.",
"fixture":"Wednesday 7pm",
"capacity":"",
"previousScore":""
},
{
"point":new GLatLng(40.211600,-74.695702),
"homeTeam":"Hamilton Library",
"awayTeam":"LUGip HW SIG",
"markerImage":"images/white.png",
"information": "Linux users can meet the first Tuesday of the month to work out harward and configuration issues.",
"fixture":"Tuesday 7pm",
"capacity":"",
"tv":""
},
{
"point":new GLatLng(40.294535,-74.682012),
"homeTeam":"Applebees",
"awayTeam":"After LUPip Mtg Spot",
"markerImage":"images/newcastle.png",
"information": "Some of us go there after the main LUGip meeting, drink brews, and talk.",
"fixture":"Wednesday whenever",
"capacity":"2 to 4 pints",
"tv":""
},
] }
答案 0 :(得分:1)
我有一个类似的脚本,它访问本地文件,并正常工作。我在这里看到的问题是你的JSON无效。也许这就是问题?
答案 1 :(得分:0)
即使页面是从文件
本地提供的,也无法使用AJAX访问本地文件