Reputation: 794
I have a textarea on a page that has its contents pushed into a mysql db with ajax/jquery $.post. then the mysql data is called with php and then pushed into a new dynamic textarea with javascript.
I convert all the html with htmlentities() before I push it into the db.
Then I run a mysql_query to drag out the data. At this point if I echo the data it echos fine.
When I then push it into a js function to create the new textarea and add the data this is where I get the error. if I try to alert the data that I got with the mysql_query I get nothing.
I am just using some Lorem Ipsum text to test. I have run firebug and the error I get is
[17:44:20.948] SyntaxError: unterminated string literal @ http://**************.com/********.php:427
I wont post all code unless anyone needs it as there is a lot and to be honest i think its some kind of escape/html encode type problem.
there is the last js function that gets the above error as per CTRL 'U'
<script>NewTextArea('1','draggable','176','672','300','300','<strong>Lorem Ipsum</strong> es simplemente el texto de relleno de las imprentas y archivos de texto. Lorem Ipsum ha sido el texto de relleno estándar de las industrias desde el año 1500, cuando un impresor (N. del
T. persona que se dedica a la imprenta) desconocido usó una galería de textos y los mezcló de tal manera que logró hacer un libro de textos especimen. No sólo sobrevivió 500 años, sino que tambien ingresó como texto de relleno en documentos electrónicos, quedando esencialmente igual al original. Fue popularizado en los 60s con la creación de las hojas "Letraset", las cuales contenian pasajes de Lorem Ipsum, y más recientemente con software de autoedición, como por ejemplo Aldus PageMaker, el cual incluye versiones de Lorem Ipsum.');</script>
Upvotes: 0
Views: 221
Reputation: 17608
When you're injecting php variables into javascript, it's safest to wrap them in a call to json_encode()
. Javascript has implicit line endings, which means newlines in strings need to be escaped. If you echo a php string with a newline as part of your javascript block, it'll break the script.
Upvotes: 3