2012年6月13日水曜日

開発環境

『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリー・ジャパン、2009年、ISBN978-4-84311-425-5) の14章(Ajaxの基礎知識)練習問題14-5解いてみる。

その他参考書籍

14-5.

コード(TextWrangler)

var xmlhttp = new XMLHttpRequest();
var drink = $('#drink').val();
drink = encodeURIComponent(drink);
var url = "recipe.php?drink=" + drink;
xmlhttp.open('GET',url,true);
xmlhttp.readystatechange = printRecipe;
xmlhttp.send(null);
function printRecipe(o){
  if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
    var text = xmlhttp.responseText;
    $('#recipe').html(text);
  }
}

0 コメント:

コメントを投稿