首页 > 解决方案 > "expression expected" error

问题描述

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 shows an error "expression expected" in the code below?

In the console shows that the error is in this part:

 <script type="text/javascript">

        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>vr</p>
<p>&nbsp;</p>
<p>ere</p>';

        $(function () {
...

complete jQuery:

<script type="text/javascript">
        var certificate = {};
        @foreach($event->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>

标签: jquerylaravel

解决方案


This should help:

@else
certificate[{{ $registrationType->id }}] = '{!!  str_replace("\r", "", str_replace("\n", "", $registrationType->certificate->content))  !!}';
@endif

So that there is no HTML string on a newline in your script.


推荐阅读