问题
I am using latest Full CKEditor (4.5.3) with Office2013 style enabled.
I added filebrowserImageUploadUrl option here:
CKEDITOR.replace( 'news_content' ,
{
"filebrowserImageUploadUrl": "/path/to/script.php"
});
When an image is uploaded, backed is returning proper HTML and headers to CKEditor, but what it does - just displays that JavaScript code and doesn't actually trigger that. If I copy-paste that JS to the browser (Chrome) console - it works (switches tab to the first one and inputs the image).
Please find screenshot attached. What have I missed?
P.S> The first argument is taken from the Request when file is being uploaded, so in that case it's = 1 (it's not the issue :))
回答1:
As it was guessed by @Wiktor the issue was in setting proper headers. I was almost there, setting wrong headers.
Right headers are obviously: "text/html" (not "plain/text", it recognizes it just as a text in this case)
$uploadResponse = new Response();
$uploadResponse->headers->set('Content-type', 'text/html');
$content = "<script type=\"text/javascript\">\n";
$content .= "window.parent.CKEDITOR.tools.callFunction(" . $funcNum . ", '/uploads/news_image/" . $response['uploadedName'] . "', '');\n";
$content .= "</script>";
$uploadResponse->setContent($content);
来源:https://stackoverflow.com/questions/32169920/uploadfile-callback-is-not-being-triggered-in-ckeditor