Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.7.3
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
Any GET request that returns JSON can be made into a flexible cross-domain accessible resource by accepting a "callback" parameter.
JSON wrapped in parentheses and prepended by some callback can become a JavaScript expression - and added dynamically to an application by appending a script tag.
Examples:
A current resource that responds to GET and accepts format=json or something similar
Request (abbreviated) -
GET /path/to/resource?format=json
Response (abbreviated) -
Content-Type: application/json
If this resource accepts a callback parameter, things might look like this
Request -
GET /path/to/resource?format=json&callback=someFunc
Response
Content-Type: text/javascript
someFunc(
{"key": "value"})
So, the three steps are:
1) wrap JSON in parentheses
2) prepend with the callback string (any arbitrary string)
3) set content type to "text/javascript"
This allows people to specify function names as callbacks. It also allows something like
GET /path/to/resource?format=json&callback=var%20someVariable%20%3D%20
and the response would look like
var someVariable = (
{"key": "value"})
(note that it is fine that the statement doesn't end with a semicolon in that case - it still makes for valid script contents)
Issue Links
- is related to
-
GEOS-2641
Allow admins to disable callback parameters in json formatted requests
-
Hum, it seems something doable. Excuse my ignorance, but why is this needed? Can't you just code them in your javascript directly?
I guess it's the "cross domain" bit that's tripping me off.
Any time frame for this one, when do you need it?