I'd just put it in a variable.

parameters : '?method=saveData&data='+data.toJSON();


--

http://positionabsolute.net

On Dec 17, 6:48 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Hi,
>
> Ajax.Updater (and the rest) don't claim to post object graphs to the
> server, and in fact they don't. They only pass name-value pairs,
> because they're doing normal HTTP GETs or POSTs, which are based on
> name-value pairs. HTTP doesn't know anything about JSON.
>
> If you want to pass an object graph, you could pass a single parameter
> with your JSON-formatted data as the value:
>
>     new Ajax.Updater(this.msg, '/inc/Calendar/Validate.php',
>         {
>             'parameters':   {json: this.toJSON()}
>         }
>     );
>
> ...and then decode the JSON-formatted data (the value of the 'json'
> parameter) on the server. There are JSON libraries for most server-
> side languages (and if there isn't one that suits your environment,
> well, the point of JSON is that it is easily parsed -- see json.org
> for details).
>
> HTH,
> --
> T.J. Crowder
> Independent Software Consultant
> tj / crowder software / comwww.crowdersoftware.com
>
> On Dec 17, 10:14 pm, Ian R <i...@fairmountfair.com> wrote:
>
> > So ok, I have this JSON string I'm trying to pass as a post.  From my
> > object's toJSON() method, I get this string:
>
> > {
> >     "anonymous_element_1": {
> >         "class": "required",
> >         "msg": ""
> >     },
> >     "anonymous_element_2": {
> >         "class": "required",
> >         "msg": ""
> >     },
> >     "public_phone": {
> >         "class": "phone",
> >         "value": "706-201-1149",
> >         "msg": ""
> >     },
> >     "private_phone": {
> >         "class": "phone",
> >         "value": "315-487-9176",
> >         "msg": ""
> >     }
>
> > }
>
> > Which is valid JSON according tohttp://www.jsonlint.com/...
>
> > However, when I try to pass this to a PHP script:
>
> >                 new Ajax.Updater(this.msg, '/inc/Calendar/Validate.php',
> >                         {
> >                                 'parameters':   this.toJSON()
> >                         }
> >                                                 );
>
> > I get nothing passed.
>
> > However, I've noticed that if I take the multidimensional aspect out
> > of it and just use the format {'key':'value,'key':'value'}, it passes
> > just fine.  Also, if I specifically set the "method" to "get", I this
> > passed in $_GET
>
> > Array
> > (
> >     [{"anonymous_element_1":_
> > {"class":_"required",_"msg":_""},_"anonymous_element_2":_
> > {"class":_"required",_"msg":_""},_"public_phone":_
> > {"class":_"phone",_"value":_"706-201-1149",_"msg":_""},_"private_phone":_
> > {"class":_"phone",_"value":_"315-487-9176",_"msg":_""}}] =>
> > )
>
> > Basically a crazy URL-encoded version of my JSON, as the key in a
> > valueless array.  Hm.
>
> > What am I doing wrong here?  I just don't get it.
>
> > Thanks in advance!
>
> > Ian

--

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.


Reply via email to