I have a little problem. I want to give the content of an array to a new
page through a form. The javascript code is:
this._view.selectedPicts.setAttribute('value', picts);
I retreive the content using mod_python:
fields = util.FieldStorage(req)
selectedPicts = fields['selectedPicts'].split(',')
All works fine under Firefox and Safari/konqueror, but fails under IE8:
Firefox:
fields={'numAdherent': [Field('numAdherent', '20')], 'numEvenement':
[Field('numEvenement', '2')], 'selectedPicts': [Field('selectedPicts',
'P4052858.JPG,PB135158.JPG,photo20-08-03_DSC5719net_redimensionner.jpg,_DSC0222.jpg,p1010005.jpg')]}
IE8:
fields={'numAdherent': [Field('numAdherent', '20')], 'numEvenement':
[Field('numEvenement', '2')], 'selectedPicts': [Field('selectedPicts',
'[object]')]}
The strange thing is if I log 'picts' before sending the form, it is
correct, even under IE8!
console.debug("OrderingController._submit(): picts=" + picts);
Firefox:
2009-11-0 12:53:55,198::DEBUG::OrderingController._submit():
picts=P4052858.JPG,PB135158.JPG,photo20-08-03_DSC5719net_redimensionner.jpg,_DSC0222.jpg,p1010005.jpg
IE8:
JOURNAL : 2009-11-0 12:55:10,67::DEBUG::OrderingController._submit():
picts=P4052858.JPG,PB135158.JPG,photo20-08-03_DSC5719net_redimensionner.jpg,_DSC0222.jpg,p1010005.jpg
So, why do I get the wrong string in my form field under IE8? What should I
use instead of just 'picts'?
Thanks,
--
Frédéric
Sorry if that's on the wrong track.
-joe t.
> i may be misunderstanding the problem you're describing, but typically
> when you submit an array of values with the same field name, you want
> to use "[]" on the end of the field name. It's possible IE is
> submitting the array in its object form, which the server is seeing as
> string "[object]" and sending back untouched. If the fields are in
> your HTML, they need an attribute like:
> <input ... name="picts[]" />
> or if the data is managed by your script, and passed in the
> Ajax.Request as part of the parameters option, you still need to wrap
> the name into a string:
> { parameters: { "picts[]" : picts ... } }
>
> Sorry if that's on the wrong track.
Thanks for the explanation.
I was wondering: a better solution is may be to use json? What do you
sthink about?
--
Frédéric
Hope that's helpful. There are much better explanations in the API
documentation, and people here in the group who can articulate it much
better than i.
-joe t.
> For most typical cases, JSON is easier, and more efficient. For one,
> by sending a Content-type header of "application/json" you can send an
> array down from the server, and Prototype automatically converts it
> into a JSON object you can utilize.
I'm switching to json, and you're right, it is much easier to handle!
--
Frédéric