JQuery로 일부 JSON에 액세스해야합니다. 어떤 이유로 든 작동하지 않으며 getJSON 메서드가 자동으로 실패하기 때문에 잘못된 점을 파악할 수 없습니다. JSON URL이 올바른지 확인했습니다. 감사!JQuery로 JSON에 액세스하기
HTML :
<html>
<head>
<script src="//code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.getJSON('../src/json/baseball.json', function(data) {
$("#add").html(data.baseball[0].levels[0].games[0].versus);
});
});
</script>
</head>
<body>
<p id= "add"></p>
</body>
</html>
JSON :
{"baseball":
[{
"gender":"boys",
"levels":[
{
"level": "varsity",
"games":[
{
"versus":"Fullerton",
"homeaway":"Home",
"month":"February",
"date":"27",
"year":"2012",
"troyscore":"32",
"vsscore":"41",
},
{
"versus":"Sunny Hills",
"homeaway":"Away",
"month":"March",
"date":"28",
"year":"2012",
"troyscore":"20",
"vsscore":"17",
}]
},
{
"level": "jv",
"games":[
{
"versus":"Sonora",
"homeaway":"Home",
"month":"January",
"date":"20",
"year":"2012",
"troyscore":"15",
"vsscore":"21",
},
{
"versus":"Valencia",
"homeaway":"Away",
"month":"April",
"date":"30",
"year":"2012",
"troyscore":"40",
"vsscore":"1",
}]
}]
},
{
"gender":"girls",
"levels":[
{
"level": "varsity",
"games":[
{
"versus":"Acacia",
"homeaway":"Home",
"month":"February",
"date":"27",
"year":"2012",
"troyscore":"32",
"vsscore":"41",
},
{
"versus":"LV",
"homeaway":"Away",
"month":"March",
"date":"28",
"year":"2012",
"troyscore":"20",
"vsscore":"17",
}]
},
{
"level": "jv",
"games":[
{
"versus":"Commonwealth",
"homeaway":"Home",
"month":"January",
"date":"20",
"year":"2012",
"troyscore":"15",
"vsscore":"21",
},
{
"versus":"Xishan",
"homeaway":"Away",
"month":"April",
"date":"30",
"year":"2012",
"troyscore":"40",
"vsscore":"1",
}]
}]
}]
}
URL이 파일 시스템 경로처럼 작동하는 것이 일반적이지만 AFAIK는 필요하지 않습니다. 서버는 보안상의 이유 때문에 적극적으로 잊어 버릴 수도 있습니다. ".."는 "상위 디렉토리"를 의미합니다. 절대 URL을 사용해 보셨습니까? – cHao
'$ ("# add") ...'앞에'console.log (data)'를 붙이면 콘솔에서 무엇을 볼 수 있습니까? – fncomp