Jose,

You are missing quotes:

var v='{{=variable}}';

In your code js thinks HOLA is an object.  If you don't want to use quotes 
on the js side you need to use extra ones in python and prevent them from 
being escaped:

variable = XML("'HOLA'")

This will get you 'HOLA' in js.  If you don't use the XML() handler you 
will get 'HOLA'

That's my assessment of the situation anyways.  Better answers are probably 
out there ;-)

lillian

On Wednesday, January 28, 2015 at 3:04:23 PM UTC-8, José Eloy wrote:
>
> Hello!
>
> How can I pass a python string to javascript? I know how to pass an 
> integer variable to javascript.
>
> Example:
>
> def pass_variable():
>     variable = 25
>     return dict(variable=variable)
>
> In the view:
> <script type="text/javascript">
>    var v={{=variable}};
>    console.log(v);
> </script>
>
> If I pass a integer variable, javascript receive it well, but if I pass a 
> string, javascript doesn't recognize it. 
>
> Now, let's assume that we use variable = "HOLA"
>
> I get the error: (using Firefox console)
> ---------------------------------------------------
> ReferenceError: HOLA is not defined
> var v = HOLA;
> ---------------------------------------------------
> What am I doing wrong?
>
> Regards.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to