npm install ember-jsonpThis README outlines the details of collaborating on this Ember addon.
This is service addon, named jsonp, providing ember-ajax -like UX with JSONP data without jQuery
https://lifeart.github.io/ember-jsonp/demo/
``
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);
`
`//api.flickr.com/services/feeds/photos_public.gne?tags=${encodedTag}&format=json
jsonp: service(),
init() {
this.set('searchTag', 'emberconf');
},
items: computed(function () {
return [];
}),
searchTag: '',
getFlickerURI() {
let encodedTag = encodeURIComponent(this.get('searchTag'));
return ;
},
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;
* paramName callback parameter namecallbackName
* callback nametimeout
* timeout (ms)uri
* or url request URLcontext
* context for success/error handlerssuccess
* success handlererror
* error handlerpattern
* callbackName pattern,
allows URL like http://site.com/jsonp?callback={{callbackName}}
where {{callbackName}} -> pattern for replacing by service
* git clone this repositorynpm install
* bower install
*
* ember serve
* Visit your app at http://localhost:4200.
* npm test (Runs ember try:testall to test your addon against multiple Ember versions)ember test
* ember test --server
*
* ember build`
For more information on using ember-cli, visit http://ember-cli.com/.