For step 1:
Don't print
the JSON directly. You'll have escaping
issues. In order to ensure the generated JSON
is valid you should
build the JSON in memory
(using Velocity/Java maps, arrays and basic
types) and then serialize it:
$jsontool.serialize({
"greeting": "Hello",
"location": "World"
})
I agree but one* purpose was to use Vincent example on
this page:
http://extensions.xwiki.org/xwiki/bin/view/Extension/Output+JSON
Perhaps we (who?) need to modify both pages?
Anyway, do you prefer this code?
{{velocity wiki="false"}}
## If AJAX call
#if("$!request.outputSyntax" != '')
$response.setContentType('application/json')
#end
#set($MyJsonData = {'greeting': 'Hello', 'location':
'World'})
$jsontool.serialize($MyJsonData)
{{/velocity}}
For step 4:
Don't hard-code the page URL and use the 'get'
action
instead of 'view' to avoid
adding view statistics entries.
var url = new
XWiki.Document('JsonHello',
'Sandbox').getURL('get');
Thxs I was too lazy to take too long time to find JS
function. :-)
Also, to avoid the need to
URL-encode the request parameters you
should
pass them using an object not a string.
var params = {
'xpage': 'plain',
'outputSyntax': 'plain'
};
$.get(url, params,
function(data) {
...
});
Yes thxs you
=> I uploaded/update my page
(The worst is that I hate JS) :-)
Pascal B
Hope this
helps,
Marius
On Fri, Mar 20, 2015 at 8:26 PM, Pascal BASTIEN
<pbasnews-xwiki(a)yahoo.fr>
wrote:
Hello,
Here, I provided an simple Ajax example to
use in xwiki application:
what I wrote is the best way (like suggest
Vincent)
Thxs.
Pascal
BASTIEN
_______________________________________________
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users