javascript - jquery unterminated string literal when loading dynamic content -
$str loading dynamic content admin panel (tinymce) in following format $str = 'first line second line third line'; when try access variable gives me unterminated string literal <script type="text/javascript"> $(document).ready(function() { var = '<?php echo $str;?>'; $('#abc').html(a); }); </script> <div id="abc"></div>
when convert string $str = 'first line second line third line';
not give error string in above way.
when dumping php variable javascript, use json_encode
. this:
var = <?php echo json_encode($str); ?>;
note no quotes around php code, important! php add quotes , escape correctly.
Comments
Post a Comment