例)Facebookに投稿した写真情報をJSON形式で取得して、HTML出力。
<!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>設置サンプル</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> <script type="text/javascript" src="/content/lib/jquery/jquery.jsonp.js"></script> <!-- JS --> <script type="text/javascript"> $(function(){ var url="https://graph.facebook.com/154272851289948&callback={callback}"; $.getJSONP(url, function(json){ var s=""; //タイトル、パーマリンク s+="<div class='title'><a href='"+json.link+"'>"+json.name+"</a><span> by "+json.from.name+"</span></div>"; s+="<div class='cf'>"; //サムネイル s+="<img src='"+json.picture+"' class='thumb' />"; //作成日、最終更新日 s+="作成日: "+relativeTime(json.created_time)+"<br>"; s+="最終更新日: "+relativeTime(json.updated_time)+"<br>"; s+="</p><p>"; //画像サイズ展開 s+="画像サイズ: "; for(var i=0; i<json.images.length; i++){ s+="<a href='"+json.images[i].source+"' target='_blank'>"+json.images[i].width+"×"+json.images[i].height+"</a> "; } s+="</p></div>"; $("#graph").append(s); }); }); function relativeTime(pastTime){ var dd = new Date(pastTime); var yy = dd.getYear(); var mm = dd.getMonth() + 1; var dd = dd.getDate(); if (yy < 2000) { yy += 1900; } if (mm < 10) { mm = "0" + mm; } if (dd < 10) { dd = "0" + dd; } return yy + "/" + mm + "/" + dd; } </script> <style type="text/css"> #graph { position:reltaive; margin:0; padding:10px; border:1px dotted #ccc; outline:1px solid #ccc; width:560px; } #graph .thumb { float:left; display:block; border:1px solid #ccc; margin:0 10px 0 0; padding:0; } #graph img { max-width:100%; } #graph p { margin:10px 0; padding:0; } #graph div.title { font-weight:bold; font-size:120%; margin:0 0 10px 0; padding:0; } #graph div.title span { font-size:80%; font-weight:normal; } </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 & JavaScript Room</a> :: 設置サンプル</h1> <h3 class='h'>実行結果</h3> <div id="wrap"> <h1>設置サンプル</h1> <p>例)Facebookに投稿した写真情報をJSON形式で取得して、HTML出力。</p> <!-- CODE --> <div id="graph"></div> <!-- / CODE --> </div> </body> </html>