Hi Bryn,
On 17 Jan 2015 at 09:43:30, Bryn Jeffries
(bryn.jeffries@sydney.edu.au(mailto:bryn.jeffries@sydney.edu.au)) wrote:
I'd like to be able to generate pure JSON from a
wiki page, to use in other pages via AJAX. To that end I created a page with the following
content:
{{velocity wiki="false"}}
$response.setContentType('application/json')
{
"greeting" : "Hello",
"location": "World"
}
{{/velocity}}
Calling this via /xwiki/bin/get/Sandbox/JsonTest I get the following code:
{
"greeting" : "Hello",
"location": "World"
}
I get the same via /xwiki/bin/view/AlertDB/JsonTest?xpage=plain.
If I remove the $response.setContentType('application/json')
https://dev.alertnessdb.net/xwiki/bin/view/AlertDB/JsonTest?xpage=plain
Inded, I would have imagine also that xpage=plain would have worked but it doesn’t. You
have to use outputsyntax.
For example:
http://playground.xwiki.org/xwiki/bin/get/Main/VMA?outputSyntax=plain
Note: You can go on a page with a livetable and check with Chrome dev tools or Firebug the
requests done and you’ll see it uses that.
Thanks
-Vincent