Find jobs - Deaf World - Moroccan Property - Find jobs - Stardoll Money Cheats

PDA

View Full Version : Using prototypejs for Ajax, how do i sent an array in the parameters?


123GoToAndPlay
Aug 16th 2007, 6:55 am
Hi all,

Part of the code i am trying


<script language="javascript" type="text/javascript">
.......
var pars = "countryname=<?php echo $countryname;?>";
new Ajax.Updater('formfields', file, { method: 'post', parameters: pars});
...........
</script>


When i set $countryname = array('fr','uk','us') i can't get the arrayvalues from countryname.

Any ideas?

bibel
Aug 17th 2007, 12:06 am
You are trying to use an php array as an javascript array.

var pars = "countryname=<?php echo $countryname;?>"; will be compiled as :
"countryname=Array".

You can either define a javascript array, or use serialise() on the php array to convert it to string, and then unserialise to change it back to an array.

123GoToAndPlay
Aug 17th 2007, 2:22 am
@bibel, that's exactly what i am trying to do.

Stupid of me to not think of serialise(), but that's was because i thought it must be in JS to enable the AJAX request.

My solution was the JSON way

//make json object...
$json = new Services_JSON();

........
var pars = 'countryname=<?php echo $json->encode($country);?>';
new Ajax.Updater('formfields', file, { method: 'post', parameters: pars});
......