accessing a PHP variable in javascript -
In my controller, I am passing this image which is an array like this:
$ this- & gt; Load-> Model ('site_model'); $ Data ['picture'] = $ this- & gt; Site_model- & gt; Fetch_imes (); $ Data ['main_content'] = 'my_view'; $ This- & gt; Load-> View ('/ template', $ data included); Everything is right to know and even I have the following elements in my view that first shows the path of the element:
< Code> $ images echo [0] ['path']; But seeing the script, I am trying to do the following: returns unwanted syntax error: unexpected token invalid " Warning ('& lt; php $ echo $ images [0] [' path '] ;;>'); Why is it so? Is not it possible
Thank you
The output you are output to has backslash The "escape sequence" in Javascript strings, which is basically a variable There is a typical representation of the tray that otherwise you would have trouble putting it in a string. But when they appear naked in a string, JS often chokes on them.
Instead of echoing the path directly, try this:
Warning (& lt;? = Json_encode ($ Picture [0] ['Path'])? & Gt;; In such a way that will cause fewer problems in JS.
(In some versions of PHP and in the configuration, probably will not work You can & lt ;? Php echo can be used instead; This is the only thing. It's just verbatim: p)
Comments
Post a Comment