1

json ファイルを読み込もうとするボタン クリックがあります。成功関数に到達することはありません。jsonファイルをローカルにロードでき、サーバーに置く必要はないと思いますか? なぜこれが機能しないのでしょうか。

$(function(){
    $('.demo').click(function(){

            $.ajax({
            url: 'data/demo.json',
            dataType: 'json',
            success: function(data){
                console.log("data = ", data)
                        }
        });

    });
});

これが私のフォルダ構造ツリーです。

  • index.html
  • データ(フォルダ)
    • デモ.json js
  • page.js

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":""
        },
] }
4

2 に答える 2

1

同様のスクリプトがあり、ローカル ファイルにアクセスして正常に動作します。ここで見られる問題は、JSON が無効であることです。たぶんそれが問題ですか?

于 2012-08-03T17:03:38.033 に答える
0

ページがファイルからローカルに提供されている場合でも、AJAX を使用してローカル ファイルにアクセスすることはできません。

于 2012-08-03T16:52:20.563 に答える