---------- Forwarded message ----------
From: Marius Dumitru Florea <mariusdumitru.florea(a)xwiki.com>
Date: Wed, Mar 25, 2015 at 10:49 AM
Subject: Re: Fw : [xwiki-users] Fw : Re: ajax example
To: Pascal BASTIEN <pbasnews-xwiki(a)yahoo.fr>
On Tue, Mar 24, 2015 at 7:34 PM, Pascal BASTIEN <pbasnews-xwiki(a)yahoo.fr> wrote:
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}}
Definitely.
Thanks,
Marius
>
>
> >
> > 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:
> > >
http://extensions.xwiki.org/xwiki/bin/view/Extension/AJAX+example#Attachmen…
> > > This mail on this list to validate that
> > 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
> >
> _______________________________________________
> users mailing list
> users(a)xwiki.org
>
http://lists.xwiki.org/mailman/listinfo/users