# Possibility to save data with javascript?

**URL:** <https://www.ruby-forum.com/t/possibility-to-save-data-with-javascript/160069>\
**Category:** Rails\
**Created:** [February 11, 2009, 2:10pm UTC](https://www.ruby-forum.com/t/possibility-to-save-data-with-javascript/160069 "2009-02-11T14:10:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andi-hro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@andi-hro](https://www.ruby-forum.com/u/andi-hro)\
**Post date:** [February 11, 2009, 2:10pm UTC](https://www.ruby-forum.com/t/possibility-to-save-data-with-javascript/160069/1 "2009-02-11T14:10:43Z")

</div>

hey,

is in ruby on rails possibility to save data with javascript?

for example to call a controller/action with parameters from a  
javascript?

thank you.

andi

---

<div class="post-metadata">

**Author:** ![andi-hro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@andi-hro](https://www.ruby-forum.com/u/andi-hro)\
**Post date:** [February 11, 2009, 2:13pm UTC](https://www.ruby-forum.com/t/possibility-to-save-data-with-javascript/160069/2 "2009-02-11T14:13:40Z")

</div>

On 11 Feb 2009, at 12:37, andi-hro wrote:

> hey,
> 
> is in ruby on rails possibility to save data with javascript?
> 
> for example to call a controller/action with parameters from a  
> javascript?

Well it’s not rails specific at all (ie. it’s just bog standard client  
side stuff) but you can make an ajax request from your javascript. The  
easiest way to get started would be to read up about that in whatever  
javascript library you’re using (prototype, jquery, mootools etc.)

Fred

---

<div class="post-metadata">

**Author:** ![andi-hro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@andi-hro](https://www.ruby-forum.com/u/andi-hro)\
**Post date:** [February 11, 2009, 9:41pm UTC](https://www.ruby-forum.com/t/possibility-to-save-data-with-javascript/160069/3 "2009-02-11T21:41:23Z")

</div>

Frederick C. wrote:

> On 11 Feb 2009, at 12:37, andi-hro wrote:  
> Well it’s not rails specific at all (ie. it’s just bog standard client  
> side stuff) but you can make an ajax request from your javascript. The  
> easiest way to get started would be to read up about that in whatever  
> javascript library you’re using (prototype, jquery, mootools etc.)

It’s not technically accurate to say that using an AJAX request is  
“saving” the data from JavaScript. You would actually be “sending” the  
data to the server, which would then save the data from the server-side.  
But, it would give you access to data stored in JavaScript variables  
allowing you to send it to the server for processing via XMLHTTPRequest  
(XHR).

Also note that you don’t actually have to use a JavaScript framework to  
use XMLHTTPRequest, but the frameworks sure make things much easier, and  
browser independent.

---

<div class="post-metadata">

**Author:** ![andi-hro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@andi-hro](https://www.ruby-forum.com/u/andi-hro)\
**Post date:** [February 13, 2009, 2:45pm UTC](https://www.ruby-forum.com/t/possibility-to-save-data-with-javascript/160069/4 "2009-02-13T14:45:43Z")

</div>

On 11 Feb., 21:41, Robert W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> But, it would give you access to data stored in JavaScript variables  
> allowing you to send it to the server for processing via XMLHTTPRequest  
> (XHR).
> 
> ## Also note that you don’t actually have to use a JavaScript framework to use XMLHTTPRequest, but the frameworks sure make things much easier, and browser independent.
> 
> Posted viahttp://www.ruby-forum.com/.

hello robert,

i tried test this:

function saveNode() {  
var lat = document.getElementById(“jsla”).value;  
var lng = document.getElementById(“jslg”).value;  
var getVars = “?node[lat]=” + lat

- “&node[name]=” + document.getElementById(“jsname”).value +  
‘\_savetest’
- “&node[lng]=” + lng
- “&node[id]=” + “55”
- “&authenticity\_token=”;  
var request = GXmlHttp.create();  
//call the create action back on the server  
request.open(‘GET’, ‘create’ + getVars, true);

}

do you know, how i can get the authenticity\_token and why there is no  
answer from the server?
