Quoting does not allways matter when setting javascript vars ... Plus not every version of php has json_encode() installed on it
Thanks Alex ----- Original Message ----- From: "Szymon Wilkołazki" <[email protected]> To: <[email protected]> Sent: Tuesday, March 03, 2009 1:17 PM Subject: [Proto-Scripty] Re: Ajax.Request and php global variable > > Alex Mcauley wrote: >> global how .. that doesnt really explain much >> >> >> If you mean globaly accessible to javascript then you need to do >> something >> like >> >> <?php >> $bar='bar'; >> echo("<script>foo=$bar</script>"); >> >> ?> >> .... > > > marioosh, you also need to properly quote strings, or convert php > variables to javascript notation. > > Easiest way to do this is to use json_encode() function: > > <?php > $bar='bar'; > echo ("<script>foo=" . json_encode($bar) . "</script>"); > ?> > > Which will give you something like: > <script>foo="bar"</script> > > If $bar was an array, eg $bar=array('one','two'), the json_encode > function would also convert it to javascript notation: > ["one", "two"]; > > Regards, > SWilk > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
