開発環境
- OS X Lion - Apple(OS)
- Safari、Firefox + Firebug (Webプラウザ、プラグイン)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- プログラミング言語:JavaScript
- JavaScript Library: jQuery
『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリー・ジャパン、2009年、ISBN978-4-87311-425-5) の14章(Ajaxの基礎)練習問第14-4、5.を解いてみる。
その他参考書籍
4, 5.
コード(BBEdit)
var $recipe = $('#recipe'),
printRecipe = function (data, textStatus, xhr) {
$recipe.html(data);
}
$.ajax({
url: 'recipe.php?drink=' + encodeURIComponent($('#drink').val()),
type: 'GET',
dataType: 'xml',
success: printRecipe,
error: function(xhr, textStatus, errorThrown) {
$recipe.text("取得失敗");
}
});
サーバー側のプログラムは用意してないけど、大体こんな感じかな〜jQueryのおかげで本書の解答より大分読みやすく、短い気がする。
0 コメント:
コメントを投稿