ܻؤ1顪30奵꡼ޥܥ

ITȤƯ30奵꡼ޥΥ饤ߥ󥰵Ͽ

jQuery

TwitterAPI˸ɤꤲɽΥץ롣

ꥯȥѥ᡼ΰ㡣
ܺ٤Ϥ򻲾
q
callbackХåؿꤷȤ
langоݤθ
rpp븡̿
pageڡ


쥹ݥ󥹥ǡϤʤ󤸡
created_atȯ
from_user桼ID
profile_image_url桼Υץե
textȯ

³ƥȥץ롣
³ɤ
    Υȥ꡼ϤƤʥ֥åޡɲ

դjsonpȤȻפä ֤ܤΥɥɲϤ­ʤ̵̤˻֤ä
˺ʤ褦˥⡣

$.ajax({
    type: "GET",
    url: "http://sample.com/",
    data: {
      "param": "hogehoge",
    },
    dataType: "jsonp",
    jsonp: "callBack",
    success: function(data) {
      /* success */
    },
    complete: function(data) {
      /* complete */
    }
});

dataTypejsonpˤjQuerycallbackѥ᡼ưƤ롣

callback=jsonp1234391216435ߤʡ

jsonpץդȢcallbackʬꤷ̾ˤǤ롣
¦APIˤäcallbackΥѥ᡼̾Ƥ礬ΤǤȤ˻Ȥ


callbackؿꤷdataץ˽񤯡

data: { "callback" : "hoge" }

callbackؿꤷʤjQueryǰʲΥɤ¹Ԥ롣
window[ 'jsonp1242391216435' ] = function(tmp){
  data = tmp;
  success();
  complete();
  // ١쥯Ƚ
  window[ jsonp ] = undefined;
  try{ delete window[ jsonp ]; } catch(e){}
  if ( head )
  head.removeChild( script );
}


¦ϤʤΤǤȤꤢǡ֤Ƥߤ
֤ǡϤˡ
<?php
$data = array("a" => "hoge", "b" => "foo", "c" => "bar");
$json = json_encode($data);
$callback = htmlspecialchars(strip_tags($_GET["callback"]));
echo $callback . "(" . $json . ")";
?>
    Υȥ꡼ϤƤʥ֥åޡɲ

ȤǥԥڤǻȤ褦˥⡣

ܸʸϤȥե졼ФƤ롣
ʡοǿ礭ۤɽ٤⤤
appid
쥹ݥ󥹷jsonxmlphp serializeǽ
*)jQueryѡ


ɤϰʲ
$(function(){
  $("#postSentence").submit(function() {
    $("#postResult").empty();
    search($("#sentence").val());
    return false;
  });
  function search(text) {
    $("#postResult").text("Now Loading....");
    $.ajax({
      dataType: "jsonp",
      data: {
        "appid":"your appid",
        "sentence":text,
        "output":"json",
        "max-result":10,
      },
      cache: true,
      url: "http://jlp.yahooapis.jp/KeyphraseService/V1/extract",
      success: function(data) {
        var ul = $(document.createElement("ul"));
        ul.addClass("class20090807");
        $.each(data, function(word, score) {
          ul.append($(document.createElement("li"))
          .append(word)
          .append(' ('+score+')'));
        });
        $("#postResult").html(ul);
      }
    });
  }
});
    Υȥ꡼ϤƤʥ֥åޡɲ

ΥڡΥȥåץ