[feature request] Would like JSONP support for xdomain api usage
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Graphite |
Fix Released
|
Medium
|
Unassigned |
Bug Description
I have a javascript app I've written to display our defined dashboards on a TV in our office. Everything works great if I load the html for the app from within the graphite tree, but I'd like to have the html live elsewhere. To do this, on usually tells jQuery to use jsonp for the json request, but the server side has to support the presence of a "callback" parameter so that the returned json gets treated as a javascript function call on the client side.
e.g.
https:/
should return:
Content-Type: application/
jQuery164014289
But only if content type is jsonp (not sure what one does that in django, but in rails, using the suffix of jsonp could do it, e.g. https:/
Regular json requests should still return text/json
Changed in graphite: | |
status: | Fix Committed → Fix Released |
I was looking for the same thing, and it looks like it's available now, at least for some operations. Instead of using the query-parameter "callback", you can use the parameter "jsonp", and this will trigger the response being wrapped in whatever that parameter's value is.
For example, this is how to get a json response with the loadavg_15min data.
http:// example. com/render? from=-2hours& until=now& width=400& height= 250&target= *.loadavg_ 15min&format= json
Adding '&jsonp=fubar', like this:
http:// example. com/render? from=-2hours& until=now& width=400& height= 250&target= *.loadavg_ 15min&format= json&jsonp= fubar
will wrap the response in fubar( ... ) and change the response content type to 'text/javascript'.
You can use the 'jsonp' configuration option with jQuery to change the callback name(Note that 'jsonp' goes in the url and in the set of ajax options). e.g.:
$.ajax({
url: 'http:// example. com/render? from=-2hours& until=now& width=400& height= 250&target= *.loadavg_ 15min&format= json&jsonp= ?',
dataType: 'json',
success: callbackFunction,
jsonp: 'jsonp'
});
This solved the issue I was having.