• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

OscarGodson/JSONP: Super Tiny JSONP Library

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

OscarGodson/JSONP

开源软件地址:

https://github.com/OscarGodson/JSONP

开源编程语言:

JavaScript 75.4%

开源软件介绍:

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



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
formio/react: JSON powered forms for React.js发布时间:2022-07-09
下一篇:
orangeduck/json2c: Convert JSON to C data literals发布时间:2022-07-09
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap