# How to marshal Javascript data?

**URL:** <https://www.ruby-forum.com/t/how-to-marshal-javascript-data/61496>\
**Category:** Rails\
**Created:** [May 24, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/how-to-marshal-javascript-data/61496 "2006-05-24T16:26:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bradley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ba0ec/32.png) [@Bradley\_M](https://www.ruby-forum.com/u/Bradley_M)\
**Post date:** [May 24, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/how-to-marshal-javascript-data/61496/1 "2006-05-24T16:26:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bradley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ba0ec/32.png) [@Bradley\_M](https://www.ruby-forum.com/u/Bradley_M)\
**Post date:** [May 24, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/how-to-marshal-javascript-data/61496/2 "2006-05-24T19:19:09Z")

</div>

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.
