# How do I get a javascript variable into rails

**URL:** <https://www.ruby-forum.com/t/how-do-i-get-a-javascript-variable-into-rails/155388>\
**Category:** Rails\
**Created:** [December 11, 2008, 10:50am UTC](https://www.ruby-forum.com/t/how-do-i-get-a-javascript-variable-into-rails/155388 "2008-12-11T10:50:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@ali](https://www.ruby-forum.com/u/ali)\
**Post date:** [December 11, 2008, 10:50am UTC](https://www.ruby-forum.com/t/how-do-i-get-a-javascript-variable-into-rails/155388/1 "2008-12-11T10:50:43Z")

</div>

Hi,

I’m new to ajax and I’ve a little problem to sending parameters in  
order to be executed on the controller.

Suppose that “function updatextable(e)” which is javascript function  
is called somewhere in the application (onDrop of draggable element).  
How can I send “e.value” to the controller in order to do some active  
record operations?

Many thanks

---

<div class="post-metadata">

**Author:** ![ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@ali](https://www.ruby-forum.com/u/ali)\
**Post date:** [December 12, 2008, 7:01pm UTC](https://www.ruby-forum.com/t/how-do-i-get-a-javascript-variable-into-rails/155388/2 "2008-12-12T19:01:23Z")

</div>

> Suppose that “function updatextable(e)” which is javascript function  
> is called somewhere in the application (onDrop of draggable element).  
> How can I send “e.value” to the controller in order to do some active  
> record operations?  
> I suppose the same way you send any data in a HTTP request, whether that  
> be by AJAX or not makes no difference.

GET: [http://example.com/resource?e=value](http://example.com/resource?e=value)

## POST: [http://example.com/resource](http://example.com/resource) – Form data – e=value

That is unless you want to take some more extreme measures like sending  
data to the server using something other than HTTP (i.e. Adobe Flash, a  
Java Applet, etc.).

---

<div class="post-metadata">

**Author:** ![ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@ali](https://www.ruby-forum.com/u/ali)\
**Post date:** [December 13, 2008, 7:33am UTC](https://www.ruby-forum.com/t/how-do-i-get-a-javascript-variable-into-rails/155388/3 "2008-12-13T07:33:50Z")

</div>

Ali wrote:

> Hi,
> 
> I’m new to ajax and I’ve a little problem to sending parameters in  
> order to be executed on the controller.
> 
> Suppose that “function updatextable(e)” which is javascript function  
> is called somewhere in the application (onDrop of draggable element).  
> How can I send “e.value” to the controller in order to do some active  
> record operations?
> 
> Many thanks

There is another topic right next to yours right now. Have a look at:  
[http://www.ruby-forum.com/topic/172754#new](http://www.ruby-forum.com/topic/172754#new)

I think it will answer your question.

jp
