0
votes

I am having a problem with ckeditor data. I have some ckeditor html data saved in my data base as a description. So when i need to update that description i need to set the data from the database and show it in the textarea in order to show user what was it. I'm using laravel 5.3. In order to do this i have tried this

var old_description = '<?php echo $Product->description;?>';
$('#detail').val(old_description);

But this is giving the following error

Uncaught SyntaxError: Invalid or unexpected token enter image description here

What is the problem and what should i do?

2

2 Answers

1
votes

You should just use json_encode() from http://www.php.net/manual/en/function.json-encode.php

var old_description = '<?php echo json_encode($Product->description); ?>';

It takes care of converting < / >, escaping any other special characters as necessary, preserve spaces, etc.

1
votes

The description you are passing contains multiple lines witch produces a javascript error. Try encoding the variable when echoing.

<?php echo json_encode($Product->description);?>