because i need to evaluate each one and i need to send other post data that 
does not need evaluating .. the other post data is not allways static so i 
cant put if/else clauses on my serverside code to accomidate it ... what i 
need is the data from the each loop send as 1 post parameter and my other 
data sent as other parameters..

I've been looking at toJSON() on the array created with the method supplied 
to me earlier ..


Also the code you quote me on was psuedo code just to try to give an idea of 
what i am trying to achieve - i know it was unworking !!!!!

Thanks
Alex


----- Original Message ----- 
From: "T.J. Crowder" <[EMAIL PROTECTED]>
To: "Prototype & script.aculo.us" <[email protected]>
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 [email protected]
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