An open API service indexing awesome lists of open source software.

https://github.com/borodean/jsonp

JSONP function in 265 bytes
https://github.com/borodean/jsonp

browser jsonp

Last synced: 5 months ago
JSON representation

JSONP function in 265 bytes

Awesome Lists containing this project

README

          

[![npm version][npm-badge]][npm] [![Build status][travis-badge]][travis] [![Coverage][coveralls-badge]][coveralls] [![Sauce test status][sauce-badge]][sauce]

# jsonp(url[, options], callback)

- `url` <String> The URL to which the request is sent.
- `options` <Object>
- `parameter` <String> The name of the JSONP query parameter. Defaults to `"callback"`.
- `object` <Object> An object to which to attach the JSONP callback. Defaults to `window`.
- `key` <String> The name of the JSONP callback. Defaults to an automatically generated unique value.
- `callback` <Function(err, data)> A callback function that receives the data.

Loads data from the server using [JSONP][jsonp]. Example:

```js
import jsonp from '@borodean/jsonp';

jsonp('https://jsfiddle.net/echo/jsonp?foo=bar', (err, data) => {
if (err) throw err;
console.log(data);
});
```

## Promise version

A version that returns a promise is also available:

```js
import jsonp from '@borodean/jsonp/promise';

jsonp('https://jsfiddle.net/echo/jsonp?foo=bar').then(
data => console.log(data),
err => console.log(err)
);
```

## Installation

```
npm install @borodean/jsonp
```

For a browser global version check the `dist` directory of the installed module or directly download it:

- [Production version][dl-callback] – 265 bytes, minified and gzipped
- [Source map][dl-callback-map]

Promise version:

- [Production version][dl-promise] – 277 bytes, minified and gzipped
- [Source map][dl-promise-map]

[coveralls]: https://coveralls.io/github/borodean/jsonp
[coveralls-badge]: https://img.shields.io/coveralls/borodean/jsonp/master
[dl-callback]: https://github.com/borodean/jsonp/releases/download/3.0.2/jsonp-3.0.2.min.js
[dl-callback-map]: https://github.com/borodean/jsonp/releases/download/3.0.2/jsonp-3.0.2.min.js.map
[dl-promise]: https://github.com/borodean/jsonp/releases/download/3.0.2/jsonp-promise-3.0.2.min.js
[dl-promise-map]: https://github.com/borodean/jsonp/releases/download/3.0.2/jsonp-promise-3.0.2.min.js.map
[jsonp]: http://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/
[npm]: https://www.npmjs.com/package/@borodean/jsonp
[npm-badge]: https://img.shields.io/npm/v/@borodean/jsonp
[sauce]: https://saucelabs.com/u/borodean-jsonp
[sauce-badge]: https://badges.herokuapp.com/sauce/borodean-jsonp
[travis]: https://travis-ci.org/borodean/jsonp
[travis-badge]: https://img.shields.io/travis/borodean/jsonp/master