2013年3月12日火曜日

開発環境

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

その他参考書籍

2, 3.

コード(BBEdit)

$('#pre0').text("");
// これはたぶん成功
$.ajax({
    url: 'http://www.mkamimura.com',
      type: 'GET',
      dataType: 'html',
      complete: function(xhr, textStatus) {
        $('#pre0').append("http://www.mkamimura.com\n");
        $('#pre0').append("complete\nxhr: " + xhr + "\ntextStatus: " +
             textStatus + "\n");
      },
      success: function(data, textStatus, xhr) {
        $('#pre0').append("http://www.mkamimura.com\n");
        $('#pre0').append("success\ntextStatus: " + textStatus + "\nxhr\n");
      },
      error: function(xhr, textStatus, errorThrown) {
        $('#pre0').append("http://www.mkamimura.com\n");
        $('#pre0').append("error\nxhr: " + xhr + "\ntextStatus: " +
            textStatus + "\nerrorThrown: " + errorThrown + "\n");
      }
});
// これは失敗
$.ajax({
    url: 'http://www.example.com',
      type: 'GET',
      dataType: 'html',
      complete: function(xhr, textStatus) {
        $('#pre0').append("http://www.example.com\n");
        $('#pre0').append("complete\nxhr: " + xhr + "\ntextStatus: " +
             textStatus + "\n");
      },
      success: function(data, textStatus, xhr) {
        $('#pre0').append("http://www.example.com\n");
        $('#pre0').append("success\ntextStatus: " + textStatus + "\nxhr\n");
      },
      error: function(xhr, textStatus, errorThrown) {
        $('#pre0').append("http://www.example.com\n");
        $('#pre0').append("error\nxhr: " + xhr + "\ntextStatus: " +
            textStatus + "\nerrorThrown: " + errorThrown + "\n");
      }
});











						

0 コメント:

コメントを投稿