dongmeiran609914 2018-07-25 17:56
浏览 393

为什么会出现此错误“无效或意外令牌”?

Im using tinymce with image upload using the package "laravel-tinymce-simple-imageupload". So I have a page where the user can select a registration type and enter some content in the tinymce textarea to associated that content to the selected registration type.

But there is an issue. For example the user can select a registration type and then in the text area write for example "certificate 1" and click in the form "Store" button. In the database the content introduced in the tinymce is stored like:

<p>certificate 1</p>

So this is correct.

But the issue is for example if the user in the text area instead of write just "certificate 1" writes "certificate 1" and then give a enter and in the next line write also for example "test" and click in the form "Store" button the page is refreshed and the tinymce buttons disappear from the textarea and the content introduced in the textarea is inserted in db like:

<p>certificate 1</p>
<p>test</p>

And it appears an error on the console: "Uncaught SyntaxError: Invalid or unexpected token" in:

 var certificate = {};
certificate[1] = 
'<p>cert1<img src="../../../img/image_1532441196_7.jpeg" 
 alt="" width="1200" height="900" /></p>';
        certificate[2] = '<p>cert2</p>
<p>&nbsp;</p>
<p>cert 2</p>
<p>&nbsp;</p>
<p>aee</p>';

But if i change in the db to "<p>certificate 1</p><p>test</p>", that is have the content in the same line, the tinymce buttons appear again when the page is refreshed.

Do you know what can be the issue?

Code in certificateController that inserts the certificate content (the content introduced in the tinymce textarea) in the DB:

 public function update(Request $request){

        $registrationType = RegistrationType::where('id', $request->registrationType)->first();

        $certificate = $registrationType->certificate;

        // if no certificate exists for this type, create it
        if(!$certificate ) {
            $certificate = new Certificate();
        }

        // the certificate_content is the textarea with the tinymce plugin
        $certificate->content = $request->certificate_content;
        $certificate->save();

        $registrationType->certificate_id = $certificate->id;
        $registrationType->save();

        $certificateContent = RegistrationType::with('certificate')->where('id', $request->registrationType)->first();

        Session::flash('success','Certificate configured with success for the selected registration type.');

        return redirect()->back();

    }

jQuery:

<script type="text/javascript">


        var certificate = {};
        @foreach($conference->registrationTypes as $registrationType)
                @if(!$registrationType->certificate)
            certificate[{{ $registrationType->id }}] = '';
        @else
            certificate[{{ $registrationType->id }}] = '{!!   $registrationType->certificate->content !!}';
        @endif
        @endforeach

        $(function () {

            $('.radio').change(function () {

                var registrationTypeId = $('input[name=registrationType]:checked').val();
                $(tinymce.get('certificate_content').getBody()).html(certificate[registrationTypeId]);
            });

            tinymce.init({
                selector: 'textarea',
                plugins: 'image code link lists textcolor wordcount ' +
                '         hr pagebreak colorpicker textpattern anchor table media',
                relative_urls: true,

                file_browser_callback: function (field_name, url, type, win) {
                    // trigger file upload form
                    if (type == 'image') $('#formUpload input').click();
                }
            });

        });


    </script>
  • 写回答

1条回答 默认 最新

  • dqy13020940 2018-07-25 18:11
    关注

    Since last year I had used tinymce plugin for generation word doc for one of my project. That time also I faced same issue. Actually in tinymce having some bugs means you have to select image twice to update and upload in system. Then it appears on webpage. In the first attempt it does not accepted. You should do one thing first you upload the image then once it accepted to system then write content.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序