Convert javascript array to a ruby array

Discussion in 'Javascript' started by David, Sep 8, 2008.

  1. David

    David Guest

    Hey can anyone help me convert a javascript array into a ruby array.
    Ive been struggling with this since friday to no avail. This is the
    function with the ajax.request call that is supposed to convert the
    array using JSON, but I keep getting a 422(Unprocessable Entity)
    error. Im not sure what is wrong.

    function test()
    {
    for(i=1;i<22;i++){
    if (document.getElementById(i+'d').className ==
    "selected"){
    myArray.push(i);
    }
    }

    new Ajax.Request('/appointments/array/',
    {method:'put',postBody:"'data='+myArray.toJSON"});

    }

    Thanks for any input!
     
    David, Sep 8, 2008
    #1
    1. Advertising

  2. David

    SAM Guest

    David a écrit :
    > Hey can anyone help me convert a javascript array into a ruby array.
    > Ive been struggling with this since friday to no avail. This is the
    > function with the ajax.request call that is supposed to convert the
    > array using JSON, but I keep getting a 422(Unprocessable Entity)
    > error. Im not sure what is wrong.
    >
    > function test()
    > {


    var myArray = [];

    > for(i=1;i<22;i++){
    > if (document.getElementById(i+'d').className ==


    could be better with :
    if (document.getElementById('d'+i).className ==
    no ?

    > "selected"){
    > myArray.push(i);
    > }
    > }


    alert('myArray = '+myArray.join(' - '));
    alert('myArray.toJSON = '+myArray.toJSON());


    > new Ajax.Request('/appointments/array/',
    > {method:'put',postBody:"'data='+myArray.toJSON"});
    >
    > }
    >
    > Thanks for any input!
     
    SAM, Sep 9, 2008
    #2
    1. Advertising

  3. David wrote:
    > Hey can anyone help me convert a javascript array into a ruby array.


    If you told us what a "ruby array" is, the chances for that would increase
    considerably.

    > [...] This is the
    > function with the ajax.request call that is supposed to convert the
    > array using JSON, but I keep getting a 422(Unprocessable Entity)
    > error.


    Useless information, without knowing what was going to be processed where
    and how.

    > Im not sure what is wrong.


    Neither can anyone else, unless you told us ...

    > function test()
    > {
    > for(i=1;i<22;i++){
    > if (document.getElementById(i+'d').className ==
    > "selected"){
    > myArray.push(i);


    what `myArray' is, ...

    > }
    > }
    >
    > new Ajax.Request('/appointments/array/',
    > {method:'put',postBody:"'data='+myArray.toJSON"});


    what `Ajax.Request' is.

    BTW: You "forgot" to declare `i' a variable.

    > }
    >
    > Thanks for any input!


    Likewise.

    <http//jibbering.com/faq/>


    PointedEars
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee
     
    Thomas 'PointedEars' Lahn, Sep 9, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    1
    Views:
    432
    Karl Seguin
    Jul 23, 2003
  2. Jaap
    Replies:
    4
    Views:
    741
    John O'Conner
    Jul 10, 2006
  3. Chris Rebert
    Replies:
    0
    Views:
    803
    Chris Rebert
    Sep 2, 2011
  4. Replies:
    6
    Views:
    165
    Elias Athanasopoulos
    Jan 11, 2004
  5. Michael Neumann

    [ANN] RubyJS - Convert Ruby to Javascript

    Michael Neumann, Jan 14, 2007, in forum: Ruby
    Replies:
    8
    Views:
    102
    Une Bévue
    Jan 15, 2007
Loading...

Share This Page