2009/7/26 Alex McAuley <[email protected]>: > > php's json_encode/decode functions... you may need to install them. > > Good luck > > > Alex Mcauley > http://www.thevacancymarket.com > > > ----- Original Message ----- > From: "geoffcox75" <[email protected]> > To: "Prototype & script.aculo.us" <[email protected]> > Sent: Sunday, July 26, 2009 6:23 PM > Subject: [Proto-Scripty] Re: what causes this? prototype/javascript/php ?! > > > > > > On Jul 26, 5:26 pm, "Alex McAuley" <[email protected]> > wrote: >> because its being sent as an array.. php cannot directly read javascript >> arrays and as such you have to json encode/decode it > > Thanks Alex - I have not so far used json - can you suggest a good > site for help on this? Simple, sample code would be very helpful to > help me get started. > > Cheers, > > Geoff > >> >> Alex Mcauleyhttp://www.thevacancymarket.com >> >> ----- Original Message ----- >> From: "geoffcox" <[email protected]> >> To: "Prototype & script.aculo.us" >> <[email protected]> >> Sent: Sunday, July 26, 2009 5:22 PM >> Subject: [Proto-Scripty] what causes this? prototype/javascript/php ?! >> >> > Hello, >> >> > I am not clear where the problem is with this situation. >> >> > The html/javascript used Ajax.Updater to send data to a php file which >> > inserts the data into mysql. >> >> > Oddly, to me ay any rate, print_r($_POST) and echo give different >> > results with chrome/safari and firefox. >> >> > With firefox I get the extra empty element and would like to know why. >> >> > Cheers, >> >> > Geoff >> >> > 1. with chrome/safari I get >> >> > (a) print_r($_POST) gives >> >> > Array ( [firstnum] => 1 [lastnum] => 3 [groupname] => test [usercode] >> > => A1 [mysql_p11] => 10 [mysql_p12] => 20 [mysql_p13] => 30 [_] => ) >> >> > (b) echo gives >> >> > 'test', >> > 'test','A1', >> > 'test','A1','10', >> > 'test','A1','10','20', >> > 'test','A1','10','20','30', >> > 'test','A1','10','20','30','', >> >> > 2. with Firefox/IE the [_] => and the '', are not present. >> >> > 3. The Javascript code >> >> > <script type="text/javascript"> >> >> > var startValue = 1; >> > var endValue = 3; >> > var p1 = []; >> > var group = "test"; >> > var code_given = "A1"; >> >> > var params = {}; >> >> > params["firstnum"] = startValue; >> > params["lastnum"] = endValue; >> > params["groupname"] = group; >> > params["usercode"] = code_given; >> >> > p1[1] = 10; >> > p1[2] = 20; >> > p1[3] = 30; >> >> > for (i=startValue;i<(endValue+1);i++) { >> > params["mysql_p1" + i] = p1[i]; >> > } >> >> > new Ajax.Updater( >> > 'updateDiv', >> > 'fv-p1-arrays4-mysql-test.php', >> > { >> > asynchronous:true, >> > method:'post', >> > parameters: params >> > } >> > ); >> >> > </script> > > > > > >
JSON Is now built into PHP as standard as of V5.3.0. Prior to that you would have to either include the pre-built library (Windows) or rebuild PHP (non-windows). The '_' comes from Prototype and is a requirement for some reason. Not exactly sure why, but you can ignore it in PHP. What are you "echo"-ing to get the list you see? If you want mysql_p1 as an array in PHP, try changing ... params["mysql_p1" + i] = p1[i]; to params['mysql_p1[' + i + ']'] = p1[i]; Regards, Richard. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" ZOPA : http://uk.zopa.com/member/RQuadling --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
