The JSONP Prefix is really useful for Cross-origin resource sharing, but for a framework like AngularJS to work the JSON Prefix needs to change according to the callback query string parameter.
A $http.jsonp('http://example.com/example.json?callback=JSON_CALLBACK') call in AngularJS changes the actual call to http://example.com/example.json?callback=angular.callbacks._0. A hardcoded JSONP Prefix to JSON_CALLBACK wouldn't work in this case and an javascript error Uncaught ReferenceError: JSON_CALLBACK is not defined is thrown.
The twitter API has the perfect solution our case, the return changes from JSON to JAVASCRIPT and the callback functions changes to what is specified by the callback query string parameter
http://api.twitter.com/1/statuses/user_timeline.json (returns JSON with content-type:application/json header)
http://api.twitter.com/1/statuses/user_timeline.json?callback=JSON_CALLBACK (returns javascript function JSON_CALLBACK with content-type:application/javascript header)
http://api.twitter.com/1/statuses/user_timeline.json?callback=ANOTHER_JS... (returns javascript function ANOTHER_JSON_CALLBACK with content-type:application/javascript header)
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | views_datasource-jsonp-callback-2010558.patch | 2.36 KB | makangus |
Comments
Comment #1
makangus commentedThis patch also fixes #2010540: JSONP Prefix should send application/javascript header.
Comment #2
yannickooI would mark this as duplicate of #1673488: JSONP has no dynamic callback because that issue was posted last year in July. Please do not merge multiple patches :)