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

実行結果

bit.ly API

現在のURLをbit.ly APIで短縮し、その戻り値をすべて表示します。

loading...

設置サンプルのソース

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>設置サンプル</title>
      <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
       <script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></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>
      <h3>bit.ly API</h3>
      <p>現在のURLをbit.ly APIで短縮し、その戻り値をすべて表示します。</p>
      <div id="loading">loading...</div>
      <script type="text/javascript">
         /* shorten.phpの中身
         */
         $(function(){
            $.getJSON(
               "/module/include/topic/bitlyapi/shorten.php", //URL短縮
               {
                  long_url:location.href
               },
               function(data){
                  var s="";
                  if(window.console && console.log) console.log(data); //debug
                  $.each(data,function(k,v){
                     if(k=="data"){
                        $.each(v,function(k2,v2){
                           if(k2=="long_url" || k2=="url"){
                              s+=k2+": <a href='"+v2+"' target='_blank'>"+v2+"</a><br>";
                           }else{
                              s+=k2+": "+v2+"<br>";
                           }
                        });
                     }else{
                        s+=k+": "+v+"<br>";
                     }
                  });
                  $("#loading").html(s);
               }
            );
         });
      </script>
   </body>
</html>