https://github.com/lifeart/ember-jsonp
Ember JSONP loader
https://github.com/lifeart/ember-jsonp
addon ember-addon ember-jsonp jsonp
Last synced: 11 months ago
JSON representation
Ember JSONP loader
- Host: GitHub
- URL: https://github.com/lifeart/ember-jsonp
- Owner: lifeart
- License: mit
- Created: 2017-04-23T00:34:25.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-07-07T18:54:17.000Z (almost 8 years ago)
- Last Synced: 2025-07-14T15:18:50.408Z (12 months ago)
- Topics: addon, ember-addon, ember-jsonp, jsonp
- Language: JavaScript
- Size: 203 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ember-jsonp
[Short description of the addon.]
This is service addon, named `jsonp`, providing `ember-ajax` -like UX with JSONP data without jQuery
## DEMO
[https://lifeart.github.io/ember-jsonp/demo/](https://lifeart.github.io/ember-jsonp/demo/)
## Usage Example
```
ember install ember-jsonp
```
```
this.get('jsonp').request(URL,context,success,error,options);
<>
this.get('jsonp').request(URL,options).then(success).catch(error);
<>
this.get('jsonp').request({url,paramName}).then(success).catch(error);
<>
this.get('jsonp').request({
url: "http://site.com?method=jsonp&callback={{callbackName}}",
pattern: "{{callbackName}}"
}).then(success).catch(error);
```
```
jsonp: service(),
init() {
this.set('searchTag', 'emberconf');
},
items: computed(function () {
return [];
}),
searchTag: '',
getFlickerURI() {
let encodedTag = encodeURIComponent(this.get('searchTag'));
return `//api.flickr.com/services/feeds/photos_public.gne?tags=${encodedTag}&format=json`;
},
searchTagDidChange: on('init', observer('searchTag', function() {
let url = this.getFlickerURI();
this.get('jsonp').request(url,this,(result)=>{
this.set('items',result.items);
},(error)=>{
console.log(error);
},{
paramName: 'jsoncallback'
});
}))
```
`ember-jsonp` generates random JSONP callback, with timeout and success/error handlers;
## Options
* `paramName` callback parameter name
* `callbackName` callback name
* `timeout` timeout (ms)
* `uri` or `url` request URL
* `context` context for success/error handlers
* `success` success handler
* `error` error handler
* `pattern` callbackName pattern,
allows URL like http://site.com/jsonp?callback={{callbackName}}
where `{{callbackName}}` -> pattern for replacing by service
## Installation
```
ember install my-addon
```
Usage
------------------------------------------------------------------------------
[Longer description of how to use the addon in apps.]
Contributing
------------------------------------------------------------------------------
### Installation
* `git clone `
* `cd my-addon`
* `npm install`
### Linting
* `npm run lint:js`
* `npm run lint:js -- --fix`
### Running tests
* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `ember try:each` – Runs the test suite against multiple Ember versions
### Running the dummy application
* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).
For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
License
------------------------------------------------------------------------------
This project is licensed under the [MIT License](LICENSE.md).