Last active
December 11, 2015 18:09
-
-
Save kawahara/4639514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> | |
</head> | |
<body> | |
<script> | |
$.ajax({ | |
type: "GET", | |
url: "http://api.rakuten.co.jp/rws/3.0/json", // URL | |
data: { | |
operation: 'SimpleHotelSearch', | |
version: '2009-10-20', | |
largeClassCode: 'japan', | |
middleClassCode: 'akita', | |
smallClassCode: 'tazawa', | |
developerId: '#YOUR_APP_ID#' // #YOUR_APP_ID#を自分のアプリIDに書き換えること | |
}, | |
dataType: "jsonp", // JSONPで取得 | |
jsonp: "callBack", // api.rakuten.co.jp で始まるドメインの場合こちらを指定 | |
success: function(data) { | |
if ('SimpleHotelSearch' in data.Body) { | |
var hotels = data.Body.SimpleHotelSearch.hotel; | |
for (var i = 0; hotels.length > i; i++) { | |
var hotel = hotels[i]; | |
if (hotel.hotelBasicInfo.hotelThumbnailUrl) { | |
// result に Element 追加 | |
$('#result').append( | |
// aタグ追加 | |
$('<a>').attr('href', hotel.hotelBasicInfo.hotelInformationUrl).append( | |
// aタグ内にimg タグ追加 | |
$('<img>').attr('src', hotel.hotelBasicInfo.hotelThumbnailUrl) | |
) | |
); | |
} | |
} | |
} | |
} | |
}); | |
</script> | |
<!-- ここに出力 --> | |
<div id="result"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment