[Seaside] Fwd: Serializing data in POST request should be different than GET

Bart Veenstra bart.veenstra at gmail.com
Sun Aug 15 16:44:13 UTC 2010

Hello there fellow smalltalkers.

I am using JQuery alot and some plugins rely on the jquery data to be
processed as a dictionary instead of a query string generated by JSJoin when
using a POST request.
By default  the data object in JQAjax is serialized like this:

bind("move_node.jstree", function(e, data) {
            data.rslt.o.each(function(i) {
                    type: "POST",
                    data: ["event=move_node.jstree", "performcopy=" +
data.rslt.cy, "id=" + $(this).attr("id"), "metadata=" +
JSON.stringify($(this).data("jstree")), "ref_id=" + data.rslt.np.attr("id"),
"ref_metadata=" + JSON.stringify(data.rslt.np.data("jstree")), "position=" +
data.rslt.cp + i, "title=" + data.rslt.name, "_s=eOxqO8i-5PB3xS69",
"_k=ep5WPiUeiuB5Jw_L", "5"].join("&"),
                    url: "/questionmanager"

Which results in a POST with the following params:


Some values are not correctly translated by javascript because everything is
presumed a String.
In this example the concatination of position goes wrong because when

position=" + data.rslt.cp + i

is executed, the variabels data.rslt.cp and i are concatinated as a string
because the whole thing is a string. So the data does not arrive in the way
I want at the server.

To fix this issue I made some changes to the data method in JQAjax:


JQAjax  data
^self options at: 'data' ifAbsentPut: [JSJoin new]


JQAjax  data
^self options at: 'data'
 [| type |
 type := self options at: 'type' ifAbsentPut: ['GET'].
 type = 'POST' ifTrue: [GRSmallDictionary new] ifFalse: [JSJoin new]].

GRSmallDictionary does not understand some methods used by the rest of
seaside, so I added them as well:

GRSmallDictionary  add: anAssociation

anAssociation isVariableBinding
 ifTrue: [self at: anAssociation key put: anAssociation value]
 ifFalse: [self at: anAssociation put: ''].

GRSmallDictionary  addAll: aCollection
 aCollection _addAllToDictionary: self.

GRSmallDictionary  collection

This results in the correct serialization of post requests:

bind("move_node.jstree", function(e, data) {
            data.rslt.o.each(function(i) {
                    type: "POST",
                    data: {
                        event: "move_node.jstree",
                        performcopy: data.rslt.cy,
                        id: $(this).attr("id"),
                        metadata: JSON.stringify($(this).data("jstree")),
                        "ref_id": data.rslt.np.attr("id"),
                        position: data.rslt.cp + i,
                        title: data.rslt.name,
                        "_s": "Ww1O92fPwzOMnyHw",
                        "_k": "nThH6d1dgDERL5ax",
                        "5": null
                    url: "/questionmanager"

with the request post parameters:


the position is now calculated correctly.

I don't know where to go from here :) Atleast it works in my Visual Works
7.7 image, But I am unfamiliar with pharo to commit this change.

Is this something Seaside could use?

And how can i control the serialization of the dictionary keys. Sometimes
the are encapsulated by double quotes, and sometimes the aren't :S.


Bart Veenstra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20100815/61a0ff4f/attachment-0001.htm

More information about the seaside mailing list