Smallest JSONp Implementation

Apr0611Apr 06, 11

Here's a tiny chunk of JavaScript I wrote while experimenting with writing an insanely small web chat client. I think this might be the worlds smallest JSONp implementation that doesn't suck.


/** Pico JSONp: */
function jsonp(u,cb){var a=jsonp._c=(jsonp._c||0)+1,b='picojsonp_'+a,c=document,d=c.body,s=c.createElement('script');window[b]=function()
{d.removeChild(s);cb.apply(cb,arguments);cb=c=d=s=null;};s.src=u.replace('{callback}',b);d.appendChild(s);}

/** Example usage: */
jsonp('http://example.com/timeline.json?callback={callback}', function(response) {
    console.log(response);
});

About Jason Miller:

I am a JavaScript developer from Waterloo, Ontario, Canada. When I am not typing green code onto a black screen, you might find me at the nearest coffee pub checking out the brew. I run a internet firm called developIT and maintain blogs and web apps when I can.
Comments
tjKomal#
its cool bro...
Tgwizman#
mhm
Leave a Comment

Post Comment