Good day,

For XHR, the answer is formed:

echo "FCKeditorAPI.GetInstance('FCKeditor_DESC').SetHTML('$DESC');"; 

Here $ DESC is arbitrary text from MySql. On the client side, data from XHR is executed directly:

 eval(data); 

Just on this line the error appears: Uncaught SyntaxError: Unexpected token ILLEGAL. htmlspecialchars () gave no result. The error appears only in Chrome; FF, IE and Opera ate the text normally.

  • @dagen niger Instead of creating clarifying answers correctly or adding updates to the original question or making clarifying comments: this corresponds to the format of the forum. - Nicolas Chabanovsky
  • Thanks for the clarification, I will know - Bodrov Andrei

3 answers 3

ABOUT! There was a theory.

If you are using xhtml, then the <br> tag must be closed: </br> .

  • <! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.0 Transitional // EN"> - Bodrov Andrey
  • As I understand it, CKeditorAPI itself converts the resulting html-code into a DOM-tree inside its field. So, he also needs to know about it :). I think it remains only to experiment with different meanings in order to understand what exactly he does not like ... - kirelagin
  • Amendment: not <br> </ br>, but <br /> - Alex Silaev
  • Damn, I always have a problem with this))) - kirelagin

Found a solution:

when \ r hit the javascript parser, chrome gave that error, unlike other browsers. Some of the descriptions that were output from the database to the $ DESC variable were copied from somewhere and contained this unprintable character, on which chrome stumbled)

the solution is to remove \ r from the string.

Thanks to everyone who helped.

    Try this:

     $DESC = 'test'; echo "FCKeditorAPI.GetInstance('FCKeditor_DESC').SetHTML('**$DESC**');"; 

    If it does, the problem is in the value of $DESC , i.e. you need not htmlspecialchars , but str_replace("'", "\\'", $DESC); .

    • Alex Silaev, the first thing he did before the question here - just substituted another value, did not help (The fact of the matter is that the problem is in the value of $ DESC. Therefore, he sinned on htmlspecialchars - Bodrov Andrei
    • @dagen niger understand again: there are no telepaths. Give more information. Do as Alex Silaev said - substitute the test line and show which line comes to the client. Show which line comes to the client, if you do not substitute test, but leave it as you have now. I put on the fact that you simply initially $ DESC variable is incorrectly filled at the level of php. - kirelagin
    • 2kirelagin This is what comes to the client and causes an error: FCKeditorAPI.GetInstance ('FCKeditor_ANNO'). SetHTML ('<div> <ul> <li> Bath </ li> <li> Framework </ li> <li> 6 injectors <b> STANDERT HM </ b>) </ li> </ ul> <br> </ div> '); But the output when $ DESC = 'test', the error is not caused: FCKeditorAPI.GetInstance ('FCKeditor_ANNO'). SetHTML ('test'); - Bodrov Andrey
    • Please show the code snippet in which the value of the data variable is assigned. And all the fragments where this variable is somehow used \ changed. And please respond to comments with comments, and not with new answers to your question :). - kirelagin pm
    • Oh, and more. How exactly did you find out that these string values ​​come to the client? The problem, for sure, lies in quotes ... - kirelagin