I've tried to load data from a JSON file into jQuery.But nothing happened.Is there anything wrong with my JSON file define or the misuse of jQuery function? Here is my json file.
{
"jQueryquiz" :
[
{
"title":"A",
"answer":"asd"
},
{
"title":"B",
"answer":"qwe"
},
{
"title":"C",
"answer":"zxc"
}
] }
Here is my hmtl file:
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(){
$('.button').click(function(){
$.getJSON('quiz.json',function(data){
var html="";
html+=data.jQueryQuiz[0].title;
$('#results').html(html);
});
});
});
</script>
</head>
<body>
<input type="button" class="button" value="Start!"/>
<div id="results">
</div>
</body>
The solution of my problem is to host the json file in some place like "myjson". The reason is just as Traveling Tech Guy said,"you can't read local files using AJAX".
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다