Anybody noticing some odd behavior with submitting forms through
Ajax.Request? I thought at first it was a problem with Form.serialize,
but was able to trace it back to line #975 (in prototype 1.5.1_rc2)
which calls "toQueryParams" on the parameters that are passed into the
new Ajax object if it is a string. This is the code (line #975 is the
second line):
if (typeof this.options.parameters == 'string')
this.options.parameters = this.options.parameters.toQueryParams();
A quick example could be seen by running the following in Firebug:
"foo=bar&apple=&orange=".toQueryParams()
The apple and orange parameters are left off due to being empty. In
terms of forms and empty fields (which should trigger validation
errors), this seems like a huge problem.
Is my version of prototype just out-of-date or is there a fix for this
in the foreseeable future? I know I can extend/override to fix this
behavior. I'm not looking for a fix, just wondering if anybody else
has seen this.
-justin
You can reproduce by doing my previous example, or even:
new Ajax.Request('/', { parameters: 'x=&y=&foo=bar' } )
Take a look at what was POSTed, it's not what you'd expect.
-justin
Sorry no-one has responded yet. It's been talked about quite a bit.
http://groups.google.com/group/prototype-core/browse_thread/thread/711012b806b3ad36/75b3de9077ec6007#75b3de9077ec6007
http://groups.google.com/group/prototype-core/browse_thread/thread/83996a20fecd61c4/8775c0b24361ae60#8775c0b24361ae60
It has been fixed in SVN and is scheduled to be in 1.5.1
> The best solution is
> to just switch forms to use normal POSTs, that's lame.
You might try passing parameters as an object instead of a string so that
toQueryParams() is not called.
new Ajax.Request('/', { parameters: { x: '', y: '', foo: 'bar' } } )
--
Michael Peters
Developer
Plus Three, LP
-justin
This has been corrected in the svn trunk:
$H("foo=bar&apple=&orange=".toQueryParams()).toQueryString()
// => "foo=bar&apple=&orange="
Regards,
Tobie
-justin