Hello,
I'd like to send a javascript object to the server using Ajax.Request
and have the parameters show up as entries in the params hash. My
javascript object contains other objects (e.g. prototype range
objects) and I'd like to maintain the same structure in my params hash
in my action function.
Initially I tried somthing like this:
var searchParams = { a: 10, b: "hello", c: $R(0,40) }
var stuff = new Ajax.Request('/browse/get_stuff', {
method: 'get',
parameters: Object.toQueryString(searchParams)
});
This almost works perfectly, but the range turns into "[Object
object]" and params.inspect returns this:
{"a"=>10, "b"=>"hello", "c"=>"[object Object]",
"action"=>"get_stuff", "controller"=>"browse"}
After reading a bit, I've come to understand that for nested objects
the preferred method is Object.toJSON rather than
Object.toQueryString. So I changed my code to this:
var searchParams = { a: 10, b: "hello", c: $R(0,40) }
var stuff = new Ajax.Request('/browse/get_stuff', {
method: 'get',
parameters: Object.toJSON(searchParams)
});
But parameters turns into a single string, rather than individual
entries in params, and params.inspect returns this:
{"action"=>"get_stuff", "{\"a\": 10, \"b\": \"hello\", \"c\":
{\"start\": 0, \"end\": 40}}"=>nil, "controller"=>"browse"}
How can I get my object hash into Ruby as a hash?
Thanks,
Mike.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---