Il 29/01/15 00:04, José Eloy ha scritto:
> 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>
>
just try this:

<script type="text/javascript">
   var v="{{=variable}}";
   console.log(v);
</script>

cheers

    M.
> 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
> <mailto:web2py+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

-- 
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