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" <wilkola...@gmail.com>
To: <prototype-scriptaculous@googlegroups.com>
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 prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to