Giter VIP home page Giter VIP logo

jsonp's Introduction

JSONP Beta 1.0

Alpha Stage

What

This is a super tiny JSONP library for when you don't need jQuery or another JS library just for JSONP requests.

Why

After searching for "JSONP examples" and "JSONP tutorials" I was dissapointed by the lack of straightforward JSONP stuff out there. While there is nothing wrong with jQuery and I use it every single day, sometimes you need to do some JSONP without using jQuery and so I wrote this for myself, but feel free to use it! The min version is only 621 bytes.

How

The high-level signature for the function looks like this:

JSONP([uri], [data], [custom_method_name], [callback])
  • uri - simply specify the endpoint you want to call. [string]
  • data - the payload that you want to include in your request. [object]
  • custom_method_name - this controls the name of the function that will make the JSONP request. Optionally used in certain cases. [string]
  • callback - a function called on a succesful response. [function]

To get my Twitter avatar for example you'd do:

JSONP('http://twitter.com/users/oscargodson.json',function(json){
  console.log(json.profile_image_url);
});

Sometimes the third-party site require a custom method name, like Flickr, which requires jsoncallback rather than the standard callback method. Here's an example to get a thumbnail of my latest pic on Flickr:

JSONP('http://api.flickr.com/services/feeds/photos_public.gne?id=12389944@N03&format=json','jsoncallback',function(json){
  console.log(json.items[0].media.m);
});

You can also pass parameters in the form of a JSON object, like so:

JSONP('https://api.github.com/users/carvefx/gists',{'since': '2014-02-01T12:00:00Z'},function(json){
  document.getElementById('github').innerHTML = json.data[0].html_url;
});

Browser Support

  • IE6+
  • Firefox 3.0+
  • Safari 4.0+
  • Google Chrome 14.0+
  • Opera 10.6+

To do...

  • Anything else people request, if anything

jsonp's People

Contributors

allen-b1 avatar duncanjbrown avatar oscargodson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonp's Issues

Awesome Work

I will be including your small jsonp library in my soon-to-be-released library. When I am finished I will send you a link to my project. Thanks again!

Greg Franko

Support headers

I don't think there is anyway to set request headers? I could probably hack this in.

CommonJS Support

I want use this lib with browserify or webpack, but it currently doesn't support CommJS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.