「jQuery入門」jsonファイルを読み込む方法
1.test.json
[
{“stuno":1001,"name":"山田"},
{“stuno":1002,"name":"杉村"},
{“stuno":1003,"name":"石田"},
{“stuno":1004,"name":"大崎"}
]
2.JSコード
<script>
$(function() {
$.getJSON(“test.json" , function(data) {
var cftTag = $(“#changfa");
for(var i = 0; i < data.length; i++) {
cftTag.append($(“<li>").attr({“stuno":data[i].stuno}).text(data[i].name));
}
});
});
</script>
3.htmlコード
<ul id="changfa"></ul>