[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) {
$.ajax({
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:
5_kep5WPiUeiuB5Jw_L_seOxqO8i-5PB3xS69eventmove_node.jstreeid
questioncategory_3metadata
{"path":"sandmin/questioncategories/questioncategory_3","id":3}performcopy
undefinedposition50ref_idquestioncategoriesref_metadata
{"path":"sandmin/questioncategories","id":"questioncategories1"}title
undefined
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:
from:
JQAjax data
^self options at: 'data' ifAbsentPut: [JSJoin new]
to:
JQAjax data
^self options at: 'data'
ifAbsentPut:
[| 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: ''].
^anAssociation
GRSmallDictionary addAll: aCollection
aCollection _addAllToDictionary: self.
^aCollection
GRSmallDictionary collection
^self
This results in the correct serialization of post requests:
bind("move_node.jstree", function(e, data) {
data.rslt.o.each(function(i) {
$.ajax({
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": "Ww1O92fPwzOMnyHw",
"_k": "nThH6d1dgDERL5ax",
"5": null
},
url: "/questionmanager"
})
})
with the request post parameters:
5_kzGF3nB7vsPFGzplS_s2H-w22qrPABNE-Fleventmove_node.jstreeid
questioncategory_4metadata
{"path":"sandmin/questioncategories/questioncategory_4","id":4}position6
ref_idquestioncategoriesref_metadata
{"path":"sandmin/questioncategories","id":"questioncategories1"}
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.
Regards,
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