UploadFile callback is not being triggered in CKEditor

别说谁变了你拦得住时间么 提交于 2019-12-02 08:36:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!