[xwiki-users] Fwd: Fw : Fw : Re: ajax example
---------- Forwarded message ---------- From: Marius Dumitru Florea <[email protected]> Date: Wed, Mar 25, 2015 at 10:49 AM Subject: Re: Fw : [xwiki-users] Fw : Re: ajax example To: Pascal BASTIEN <[email protected]> On Tue, Mar 24, 2015 at 7:34 PM, Pascal BASTIEN <[email protected]> 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 <[email protected]> wrote:
Hello,
Here, I provided an simple Ajax example to use in xwiki application: http://extensions.xwiki.org/xwiki/bin/view/Extension/AJAX+example#Attachment... This mail on this list to validate that what I wrote is the best way (like suggest Vincent)
Thxs.
Pascal BASTIEN
_______________________________________________
users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Thxs I updated my page and precise the source (you :-) ) http://extensions.xwiki.org/xwiki/bin/view/Extension/AJAX+example I thinks this page is better in developpment section, no? Because it is not a usefull extension, except to explain/show a nice ajax example in Xwiki. WDYT? -------------------------------------------- En date de : Mer 25.3.15, Marius Dumitru Florea <[email protected]> a écrit : Objet: [xwiki-users] Fwd: Fw : Fw : Re: ajax example À: "XWiki Users" <[email protected]> Date: Mercredi 25 mars 2015, 9h50 ---------- Forwarded message ---------- From: Marius Dumitru Florea <[email protected]> Date: Wed, Mar 25, 2015 at 10:49 AM Subject: Re: Fw : [xwiki-users] Fw : Re: ajax example To: Pascal BASTIEN <[email protected]> On Tue, Mar 24, 2015 at 7:34 PM, Pascal BASTIEN <[email protected]> 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
<[email protected]> wrote:
Hello,
Here, I provided an simple
Ajax example to use in xwiki application:
http://extensions.xwiki.org/xwiki/bin/view/Extension/AJAX+example#Attachment... This mail on this list to validate that what I wrote is the best way (like suggest Vincent)
Thxs.
Pascal
BASTIEN
users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (2)
-
Marius Dumitru Florea -
Pascal BASTIEN