Notes & Code Snippets

Read notes about design & development, or useful scripts and bits of code from me

Connecting to Flickr

November 19, 2013

Keywords: js javascript json

Keeping this for reference, settings needed to connect to Flickr's API
 
$.ajax({
	url: 'http://api.flickr.com/services/rest/',
	data: {
		method: 'flickr.people.getPublicPhotos',
		api_key: '4ef2fe2affcdd6e13218f5ddd0e2500d',
		user_id: '29096781@N02',
		format: 'json',
	},
	jsonp: 'jsoncallback',
	type: 'GET',
	dataType: 'jsonp',
	success: function(d){
		console.log(d);
	},
	error: function(e){
		console.log('error!');
		console.log(e);
	}
})

Back to top

Javascript print_r equivalent

December 29, 2008

Keywords: javascript java script print_r printr php equivalent

Useful Javascript function that mimics PHP's print_r function.
function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>[" p "] => " typeof(theObj) "</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>[" p "] => " theObj[p] "</li>");
      }
    }
    document.write("</ul>")
  }
}

Back to top