「ajax入門」jsonデータを取得するサンプルコード

1.ajaxコード
$.ajax({
type: “GET",
url: “xxxx.json",
dataType:"json",
success: function (data) {
for (var i = 0 – 1; i < data.length; i++;) {
$('li’).append(data[i].address + ' – ' + data[i].ticket);
};
},
error: function (XMLHttpRequest, textStatus, errorThrown) {

console.log(XMLHttpRequest + '-' + textStatus + '-' + errorThrown);
}
});

2.jsonデータ
[
{
“address": “oosaki",
“ticket": “340"
},
{
“address": “ooimati",
“ticket": “216"
},
{
“address": “shinagawa",
“ticket": “170"
}
]

JavaScript

Posted by arkgame