When you Assigned multi-line PHP string variable to
javascript variable then it will create “SyntaxError: unterminated string
literal” which you can see in console section if firebug extension is installed
in your Mozilla firefox browser.
If you are assigning a string value which contain new line
characters or HTML in more than one line and this variable will further used as
a value in some Jaascript variable then you have to use PHP addcslashes() function before sending.
Let’s see how you can do this:
In PHP:
$product_desc = addcslashes($_simpleproduct['description'],"\\\'\"\n\r");
In Javascript:
var pro_desc = '<?php echo $product_desc; ?>';
var pro_desc = '<?php echo $product_desc; ?>';
var pro_desc = '<?php echo $product_desc; ?>';
Now, above code will
work fine and will display no more error in firebug console and also no more
headche in your head.
0 Comments