PHP & JavaScript Room :: 設置サンプル

実行結果

非同期通信:Ajaxイベント:ajaxStop(callback)の使用例 | jQuery

▼Ajaxリクエストが開始されまだアクティブになっていない時に読込中メッセージを表示し、リクエストが終了した時に読込中メッセージを非表示にします。

読込中・・・

設置サンプルのソース

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta http-equiv="Content-Language" content="ja" />
      <meta http-equiv="Content-Script-Type" content="text/javascript" />
      <meta http-equiv="Content-Style-Type" content="text/css" />
      <meta http-equiv="imagetoolbar" content="no" />
      <title>非同期通信:Ajaxイベント:ajaxStop(callback)の使用例 | jQuery</title>
      <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
      <!-- JS -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
      <script type="text/javascript">
         $(function(){
            $("#res").hide();
            /* 指定したファイルを読み込んで表示 */
            function loadData(filename){
               $.get(filename, function(data,stat){
                  $("#res").text(filename+"の内容:<br>"+data).show();
               });
            }
            /* Ajaxリクエストが開始されまだアクティブになっていない時に読込中メッセージを表示する */
            $("#loading").ajaxStop(function(){
               $(this).show();
            });
            /* Ajaxリクエスト終了時に読込中メッセージを非表示にする */
            $("#loading").ajaxStop(function(){
               $(this).hide();
            });
            loadData("data/data_ajax.csv");
         });
      </script>
      <style type="text/css">
         #loading { color:blue; font-size:2em; font-weight:bold; }
         #res { background-color:#fff; border:1px solid #ccc; padding:10px; height:100px; overflow:auto; }
      </style>
   <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
   <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP &amp; JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
      <div id="wrap">
         <h1>非同期通信:Ajaxイベント:ajaxStop(callback)の使用例 | jQuery</h1>
         <p>▼Ajaxリクエストが開始されまだアクティブになっていない時に読込中メッセージを表示し、リクエストが終了した時に読込中メッセージを非表示にします。</p>
<!-- CODE -->
         <p id="loading">読込中・・・</p>
         <div id="res"></div>
<!-- CODE / -->
      </div>
   </body>
</html>