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

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

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 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛