Prototype Form.serialize(this) merging with another hash
I'm trying to merge a form hash with another hash using Prototype (1.6.0.3)
This doesn't pass any parameters to the server
<a href="#" onclick="new Ajax.Request('/users', {asynchronous:true, evalScripts:true, parameters:$H(Form.serialize(this, true)).merge({order: 'descend_by_created_by'})}); return false;">Name</a>
but this does
<a href="#" onclick="new Ajax.Request('/users', {asynchronous:true, evalScripts:true, parameters: Form.serialize(this, true)}); retur开发者_如何学编程n false;">Name</a>
Any ideas on how to fix this? I don't get any javascript errors.
Looks like this is an issue with the old version of the Prototype docs:
That's a documentation issue. Expected output (from Form.serialize) is a vanilla JS object, not a hash https://groups.google.com/group/prototype-core/browse_thread/thread/d686de54683b206c?pli=1
UPDATE
You can achieve what you want like this:
<a href="#" onclick="new Ajax.Request('/users', {asynchronous:true, evalScripts:true, parameters: Object.extend(Form.serialize(true), {order: 'descend_by_created_by'})}); return false;">Name</a>
This makes use of Object.extend:
Object.extend(Form.serialize(true), {order: 'descend_by_created_by'})
精彩评论