I  suppose what i need is a push into my json object method ... though i 
cant seem to find a working one in prototypejs ..

merge(); and update(); both seem to want to be used with $H() but it updates 
with my var ...

Something like {"l" : "doe"}

when it should be {"surname" : "doe"};

plus it doesnt merge each of them !! it only merges the last one !!

Regards
Alex



----- Original Message ----- 
From: "T.J. Crowder" <[EMAIL PROTECTED]>
To: "Prototype & script.aculo.us" <prototype-scriptaculous@googlegroups.com>
Sent: Monday, November 17, 2008 1:05 PM
Subject: [Proto-Scripty] Re: Sending Json to the server



Alex,

Why send it to the server in JSON format as opposed to standard POST
encoding?  If all you want is key/value pairs, just sending POST data
seems much more straight-forward.

Separately, on the code:

> $$('.formJson').each(function(e) {
> var p=$(e).dbCol + $(e).value;
> var d=p.toJSON();
> params.push(d);}

$$ returns extended elements[1], so no need to extend them again (much
less repeatedly).  Also, when creating 'p', you're not putting any
kind of delimiter between the dbCol property and the value, so you'll
get a string like "surnameDoe".  Also, you're expecting to be able to
access an attribute of an element ('dbCol') as thought it were a
property of the Element object; you can't.  You can get it via
Prototype's readAttribute method[2], though.

[1] http://www.prototypejs.org/api/utility/dollar-dollar
[2] http://www.prototypejs.org/api/element/readAttribute
--
T.J. Crowder
tj / crowder software / com

On Nov 17, 11:51 am, Jeztah <[EMAIL PROTECTED]> wrote:
> Morning Guys ...
>
> I am having a real headache trying to send json data to the server and
> have php decode it so i can do something with the data ..
> .
> Basically what i am trying to do is...
>
> I have a form and i would like to send data to the server in Json form
> (key/value pairs) so i can go over it in a loop with php cehcking
> somehting against a database...
>
> I did think of serialize() but i need to send information in a custom
> tag thats in some input values somethin like
>
> <input type="text" id="foo_12323142341234" class="formJson"
> dbCol="forename" value="John" />
> <input type="text" id="foo_12323142344321" class="formJson"
> dbCol="surname" value="Doe" />
> and have in the json
> var params=new Array();
> $$('.formJson').each(function(e) {
> var p=$(e).dbCol + $(e).value;
> var d=p.toJSON();
> params.push(d);}
>
> to end up with something like .....
> "forename" : "John",
> "surname" : "Doe"
>
> toJSON() seems to not be playing nice and tells me its not a function
>
> Can anyone think of a way to encode all the elements with the
> className of 'formJson' grabbing the custom tag (dbCol) and the value
> of the element into an object or an array and send it to the server
> (running php 5.2) so i can process it on the server end ..
>
> I've been scratching my head over it all morning and cant find a
> solution !!
>
> Regards
> Alex



--~--~---------~--~----~------------~-------~--~----~
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-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to