You can send the data any way you want, just so long as your  
unserialize matches your serialize.

The first question I'd ask though, is why?  Can't you simply send  
"key1=val1&key2=val2", then assign the resulting $_POST array on the  
PHP side to $flip?

<?php //i.e.
$flip = $_POST;
print_r($flip);
?>

Perhaps you need to rethink your architecture.  Despite my objection  
to your methodology, here are a few solutions:

1) If you want your PHP backend to unserialize automagically, set  
your query string to:
flip[key1]=val1&flip[key2]=val2;

You may have to do this by hand; I don't think $H().toQueryString  
handles nested hashes well.

2) Or, you could send "flip" as a JSON string.  Prototype doesn't  
have the object->JSON string conversions (yet), but there are several  
libraries that you can easily find through Google.  In this case,  
your query string might look like:
flip={"key1":"val1","key2":"val2"}.  You'd have to JSON->PHP on the  
server side.  There is a PECL object for this; it's part of the PHP  
core as of ver 5.2.
http://us3.php.net/manual/en/function.json-decode.php

3) A third method, might be this:
var tmp = $H({
        flip: encodeURIComponent($H({
                key1: 'val1',
                key2: 'val2'
        }).toQueryString())
}).toQueryString();

... then on the PHP server side use parse_str($_POST['flip'], $_POST 
['flip'])
http://us3.php.net/manual/en/function.parse-str.php
or perhaps HttpQueryString::toArray() (part of the PECL HTTP library).
http://us3.php.net/manual/en/http.HttpQueryString.php



TAG

On Feb 23, 2007, at 4:25 AM, Jussi Salminen wrote:

> Can I pass JSON object or multidimensional JS array to server?
>
> Next case almost explode my head...
>
> I've got js array
> flip[key1] = 'val1';
> flip[key2] = 'val2';
>
> and when I send it to server , it's look like
> key1 => val1,
> key2 => val2
>
> but I want out:
> flip =>
>          key1 => val1,
>          key2 => val2
>
> Is this possible or not?
> Or could that array set to php serialized string?
>
>
> ******************************************
> Jussi Salminen
> [EMAIL PROTECTED]
> +358 45 630 1723
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@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-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to