0

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 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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);?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.