[feature request] Would like JSONP support for xdomain api usage

Bug #862598 reported by Matt Conway
22
This bug affects 5 people
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://server.name/graphite/dashboard/find/?callback=jQuery164014289093087427318_1317316003234

should return:

Content-Type: application/javascript
jQuery164014289093087427318_1317316003234({"dashboards": [{"name": "MyDash"}]});

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://server.name/graphite/dashboard/find.jsonp?callback=jQuery164014289093087427318_1317316003234

Regular json requests should still return text/json

Revision history for this message
Daniel Cartoon (dcartoon) wrote :

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.

Revision history for this message
Michael Leinartas (mleinartas) wrote :

Marking this as committed as jsonp parameter as described below is now available for /browser, /render, /metrics, and /graphlot
This was added in r493, r519, r745, r755

Changed in graphite:
importance: Undecided → Medium
milestone: none → 0.9.10
status: New → Fix Committed
Changed in graphite:
status: Fix Committed → Fix Released
Revision history for this message
Nat Pryce (nat-pryce) wrote :

JSONP does not seem to be supported for the /find/ URL.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.