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

実行結果

jQuery::非同期通信::Ajaxリクエスト::jQuery.post(url[, data[, callback[, type]]])の使用例

phpページのコンテンツ(<?php echo json_encode(array("name"=>"John","time"=>"2pm"));?>)をJSON形式に変換して取得します。

設置サンプルのソース

<!DOCTYPE html>
<html lang="ja">
<head>
   <meta charset="utf-8">
   <title>jQuery::非同期通信:Ajaxリクエスト::jQuery.post(url[, data[, callback[, type]]])の使用例</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>
      $(function(){
         $.post("/content/demo/jquery_post.php", { func: "getNameAndTime" },
            function(data){
               $("#res").html("data.name="+data.name+"<br>data.time="+data.time);
            },
            "json"
         );
       });
   </script>
<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>
<!-- CONTENT -->
   <h1>jQuery::非同期通信::Ajaxリクエスト::jQuery.post(url[, data[, callback[, type]]])の使用例</h1>
   <p>phpページのコンテンツ(&lt;?php echo json_encode(array("name"=>"John","time"=&gt;"2pm"));?&gt;)をJSON形式に変換して取得します。</p>
<!-- CODE -->
   <div id="res"></div>
<!-- / CODE -->
<!-- / CONTENT -->
</body>
</html>