JavaScript: JSONP Quick Ref & Service List

January 17th, 2010 by jeremychone

JSONP quick sample with Twitter

var tweeturl = "http://search.twitter.com/search.json?count=2&q=HAITI&callback=?";
  $.getJSON(tweeturl, function(data){
	      $.each(data.results, function(i, item) {
		    $('<p></p>')
		        .addClass(i%2 ? 'even' : 'odd')
		        .html(item.text)
			.prepend("<img src='" + item.profile_image_url + "' />")
		        .appendTo('#testDiv');

		  });
  });

Result:

{
   "results":[
      {
         "profile_image_url":"http://a1.twimg.com/profile_images/339499068/LaCroixLogoBlu2_normal.jpg",
         "created_at":"Mon, 08 Mar 2010 02:16:46 +0000",
         "from_user":"LaCroixChurch",
         "to_user_id":null,
         "text":"Geaux Haiti! "Far Away" by Lecrae... Powerful song for a honorable cause. Keep praying for Haiti brothers and... http://bit.ly/bbc7Za",
         "id":10148624077,
         "from_user_id":31526514,
         "geo":null,
         "iso_language_code":"en",
         "source":"<a href="http://www.facebook.com/twitter" rel="nofollow">Facebook</a>"
      },
   .....

Twitter JSON Search result

Services supporting JSONP

Feel free too add new one as comment I will update this page

Leave a Reply