Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a JSONP API in AngularJS & consume with jQuery
    text
    copied!<p>Right now I've created a JS API with JQuery, but I'm wondering if it could be done with AngularJs.</p> <p>For example, Imagine a small API like the following:</p> <pre><code>var $myapi= $myapi|| {}; ;(function($, window, document, undefined){ _call_myapi_jsonp: function(params,controller,action,eventName){ if (!params) params = {}; var url = this.urls.base+"/"+controller+"/"+action+"?callback=?"; if (params.callback) url = this.urls.base+"/"+controller+"/"+action+"?callback="+params.callback; url = url + "&amp;_"+new Date(); delete params.callback; $.ajax({ url: url, data: params, crossDomain:true, dataType:'jsonp', cache:false, ajaxOptions: {cache: false}, jsonp: params.callback?false:true, success:function(data,status){ if (eventName &amp;&amp; eventName!=""){ $($myapi).trigger(eventName,data); } } }); }, level: { list: function(params){ params = params || {}; params.max = params.max!=undefined?parseInt(params.max):$myapi.defaults.levels.max; params.page = params.page!=undefined?parseInt(params.page):$myapi.defaults.levels.page; params.showActives = params.showActives!=undefined?params.showActives:$myapi.defaults.levels.showActives; $myapi._call_myapi_jsonp(params,"level","listJSONP","myapi.level.list"); }, info: function(params){ $myapi._call_myapi_jsonp(params,"level","showJSONP","myapi.level.info"); } } } </code></pre> <p>I've been searching through AngularJs Documentation and also searching in Google, but I have not found a way in which the code in Jquery could be made in AngularJS. I thought maybe using $routeProvider it could be done, but I have'nt found any example nor documentation on how to use $routeProvider to make jsonp calls without showing a template or redirecting to some place.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload