How to marshal Javascript data?


#1

I’m trying to marshal some information I have in Javascript, and send
it over an AJAX request to the server, specifically to be stored in a
model on the server side.

I have some Javascript routines I wrote that gather information about
the user selection. I see that the link_to_remote has a :before
option in which I can write Javascript to collect what I need, but
right now I’m at a bit of a loss as to how to do it.

What I would like to do is present the user with a link. On
invocation of the link, my Javascript function is invoked, returning
an object with all the relevent data I need (mostly just numeric
data). Now I want to send the data to the server.

How do I marshall that data up and send it to the server? Do I have
to somehow wrap all this in some sort of form containing only hidden
fields? Am I coming at this from the right direction? What’s the
right way to do it?

Thanks,
Brad


#2

just use javascirpt and the prototype.js lib directly and not just the
rails
helper and you get all you need. if you send the data as
JSON-serialized,
than it is easy to handle it at rails serverside, but I do not know
whether
prototype.js has specific JSON support.