Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在summer Notes中加载数据时,JS弹出一个意外标识符错误_Javascript_Php_Jquery_Summernote - Fatal编程技术网

Javascript 在summer Notes中加载数据时,JS弹出一个意外标识符错误

Javascript 在summer Notes中加载数据时,JS弹出一个意外标识符错误,javascript,php,jquery,summernote,Javascript,Php,Jquery,Summernote,我使用summer note作为文本编辑器,替代wp编辑器来创建帖子。当通过summer便笺创建帖子并将其发送到服务器时,它被成功创建,但当我想要编辑同一帖子(,其中包含单引号或双引号)时,JS显示意外标识符的错误,并停止加载代码。下面我分享了我在过去5天里试着编辑的代码,但现在我放弃了,无法理解哪里出了问题 -----------这是我用来创建帖子的代码块,我将发布HTML、Jquery、ajax和PHP代码----------- HTML: <div class="col-md-9"&

我使用summer note作为文本编辑器,替代wp编辑器来创建帖子。当通过summer便笺创建帖子并将其发送到服务器时,它被成功创建,但当我想要编辑同一帖子(,其中包含单引号或双引号)时,JS显示意外标识符的错误,并停止加载代码。下面我分享了我在过去5天里试着编辑的代码,但现在我放弃了,无法理解哪里出了问题

-----------这是我用来创建帖子的代码块,我将发布HTML、Jquery、ajax和PHP代码-----------

HTML:

<div class="col-md-9">
   <textarea name="post_content" id="post_content" class="form-control round post_content summernote"></textarea>
</div>
function clean_html(editor, type, value)
{
    if (value.indexOf("<"+type+">") >= 0)
        {
            if(type == "b")
                {
                    marca = /<b(?:.*?)>(?:.*?)<\/b>/g;
                    replaceIniTag = "<strong>";
                    replaceEndTag = "</strong>";
                }
            else
                {
                    marca = /<i(?:.*?)>(?:.*?)<\/i>/g;
                    replaceIniTag = "<em>";
                    replaceEndTag = "</em>";
                }
            var matches = value.match(marca), 
            len = matches.length,
            i;
            for (i = 0; i < len; i++)
                {
                    str = $(matches[i]).text();
                    str = replaceIniTag+str+replaceEndTag;
                    value = value.replace(matches[i], str);
                }
            $('#post_content').summernote('code', value); //Replace the editor content
        }
}

function CleanPastedHTML(input)
{
    // 1. remove line breaks / Mso classes
    var stringStripper = /(\n|\r| class=(")?Mso[a-zA-Z]+(")?)/g;
    var output = input.replace(stringStripper, ' ');
    // 2. strip Word generated HTML comments
    var commentSripper = new RegExp('<!--(.*?)-->','g');
    var output = output.replace(commentSripper, '');
    var tagStripper = new RegExp('<(/)*(meta|link|span|\\?xml:|st1:|o:|font)(.*?)>','gi');
    // 3. remove tags leave content if any
    output = output.replace(tagStripper, '');
    // 4. Remove everything in between and including tags '<style(.)style(.)>'
    var badTags = ['style', 'script','applet','embed','noframes','noscript'];

    for (var i=0; i< badTags.length; i++)
        {
            tagStripper = new RegExp('<'+badTags[i]+'.*?'+badTags[i]+'(.*?)>', 'gi');
            output = output.replace(tagStripper, '');
        }
    // 5. remove attributes ' style="..."'
    var badAttributes = ['style', 'start'];
    for (var i=0; i< badAttributes.length; i++)
        {
            var attributeStripper = new RegExp(' ' + badAttributes[i] + '="(.*?)"','gi');
            output = output.replace(attributeStripper, '');
        }
    return output;
}

$('#post_content').summernote(
{
    height: 200,
    focus: false,
    disableDragAndDrop: true,
    popover: {
                image: [],
                link: [],
                air: []
              },
    // disableResizeEditor: true,
    placeholder: "Type Your Post Content...",
    toolbar: [
                ['cleaner',['cleaner']], // The Button
                ['style', ['style']],
                // ['style', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']],
                ['style', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript']],
                // ['fontname', ['fontname']],
                ['fontsize', ['fontsize']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['height', ['height']],
                ['table', ['table']],
                ['insert', ['link', 'hr']],
                // ['insert', ['link', 'picture', 'video', 'hr', 'readmore']],
                ['view', ['fullscreen', 'codeview']]
                // ['help', ['help']]
            ],
    cleaner:{
                  action: 'both', // both|button|paste 'button' only cleans via toolbar button, 'paste' only clean when pasting content, both does both options.
                  newline: '<br>', // Summernote's default is to use '<p><br></p>'
                  notStyle: 'position:absolute;top:0;left:0;right:0', // Position of Notification
                  icon: '<i class="note-icon-row-remove"></i> &nbsp;Clean',
                  keepHtml: false, // Remove all Html formats
                  keepOnlyTags: ['<p>', '<br>', '<ul>', '<li>', '<b>', '<strong>','<i>', '<a>'], // If keepHtml is true, remove all tags except these
                  keepClasses: false, // Remove Classes
                  badTags: ['style', 'script', 'applet', 'embed', 'noframes', 'noscript', 'html'], // Remove full tags with contents
                  badAttributes: ['style', 'start'], // Remove attributes from remaining tags
                  limitChars: false, // 0/false|# 0/false disables option
                  limitDisplay: 'both', // text|html|both
                  limitStop: false // true/false
            },
        callbacks:
            {
                onPaste: function (e)
                    {
                        var thisNote = $(this);
                        var updatePastedText = function(someNote)
                            {
                                var original = someNote.code();
                                var cleaned = CleanPastedHTML(original); //this is where to call whatever clean function you want. I have mine in a different file, called CleanPastedHTML.
                                someNote.code('').html(cleaned); //this sets the displayed content editor to the cleaned pasted code.
                            };
                        setTimeout(function ()
                            {
                                //this kinda sucks, but if you don't do a setTimeout, 
                                //the function is called before the text is really pasted.
                                updatePastedText(thisNote);
                            }, 10);
                    },
                onChange: function(contents, $editable)
                    {
                        clean_html(this, "b", contents);
                        clean_html(this, "i", contents);
                    }
            }
});

$('#post_content').summernote('removeModule', 'autoLink');
var post_content = $("#post_content").summernote('code');

$.ajax({
    url: '/bypasser/modules/create.php',
    type: 'POST',
    dataType: 'JSON',
    data: {action: "create", type: "post", title: post_title, slug: post_slug, category: post_category_id, content: post_content, excerpt: post_excerpt, tags: post_tags, featured_image: response, original_image: $original_image, status: post_status},
    success:function(resp)
        {
            if(resp.status == "success")
                {
                    $("#post_title, #post_slug, #post_content, select.post_category, #post_excerpt, #post_tags, #upload_image, #post_status, #post_preview, #post_create").attr("disabled", false);
                    $('#post_content').summernote('enable');
                    $('#post_content').summernote('reset');
                }
        }
});
PHP代码:(我已经删除了rest代码,因为它是不需要的)


当我编辑这篇文章时,上面的rest代码是一样的,唯一的事情是我必须把这些值放在summer note中,所以我必须通过JS实现它,下面是代码。
标记中的代码加载到PHP文件中,而另一个代码加载到
.js
文件中

<script>
   var htmlCode = "<?php echo htmlspecialchars_decode($content); ?>";
</script>

$('#post_content').summernote('code', htmlCode);
以下是检查时发布的内容:

<script>
    var htmlCode = "<p>Whatsapp for iOS now lets users completely ignore muted chat. Also, the recently now added group privacy options. </p><p> I<span style="font-size: 1rem;">ndian users of Fitbit least active and most sleep deprived - Fitbit the wearables brand. </span></p><p><span style="font-size: 1rem;"> Apple&rsquo;s latest AirPods Pro launched in India at Rs. 24,900 with active noise cancellation.&nbsp;</span><span style="font-size: 1rem;">The truly wireless pair of earphones will be available with Apple&rsquo;s authorised resellers.</span></p><p><span style="font-size: 1rem;"> Google to secure G Pay transactions with biometrics. The latest 2.100 version shows facial recognition and fingerprint features. </span></p><p><span style="font-size: 1rem;">  MTNL users get two 1Gbps plans, for 2,990 and 4,990. The plans are now restricted to Delhi. </span></p><p><span style="font-size: 1rem;">Jio All-in-one plans start at Rs.222 post introduction of 6ps/min call charges for Jio to non-Jio calls.&nbsp;</span></p>";
</script>

变量htmlCode=“Whatsapp for iOS现在允许用户完全忽略静音聊天。此外,最近添加的组隐私选项

印度用户的Fitbit活动最少,睡眠最缺乏——Fitbit是可穿戴设备品牌

苹果公司;s最新的AirPods Pro在印度推出,售价为24900卢比,具有主动噪声消除功能。Apple&rsquo;将提供真正的无线耳机;谷歌的授权经销商。

谷歌利用生物识别技术保护G支付交易。最新的2.100版本显示了面部识别和指纹特征

MTNL用户可以获得两个1Gbps计划,分别为2990和4990。这些计划现在仅限于德里

Jio多功能一体计划从222卢比开始,为Jio至非Jio通话引入6ps/min通话费

“;

在过去的5天里,我一直在解决这个问题,不知道该怎么办。有人能告诉我哪里出了问题吗?

我希望这能帮助别人,你可以使用back tick(`)字符以允许单引号和双引号,我不确定当您的字符串也包含回勾时这将如何表现,但到目前为止我一直在使用它。 这通常对我有用,希望对你有帮助

    var htmlFromDatabase = `<?php echo $topic['topicContent']; ?>`
    $("#topicContent").summernote('code', htmlFromDatabase);
var htmlFromDatabase=``
$(“#主题内容”).summernote('code',htmlFromDatabase);

什么是由
打印的内容?我用打印的内容编辑了这篇文章,请看一看。@VLAZ你能帮我吗?
<script>
    var htmlCode = "<p>Whatsapp for iOS now lets users completely ignore muted chat. Also, the recently now added group privacy options. </p><p> I<span style="font-size: 1rem;">ndian users of Fitbit least active and most sleep deprived - Fitbit the wearables brand. </span></p><p><span style="font-size: 1rem;"> Apple&rsquo;s latest AirPods Pro launched in India at Rs. 24,900 with active noise cancellation.&nbsp;</span><span style="font-size: 1rem;">The truly wireless pair of earphones will be available with Apple&rsquo;s authorised resellers.</span></p><p><span style="font-size: 1rem;"> Google to secure G Pay transactions with biometrics. The latest 2.100 version shows facial recognition and fingerprint features. </span></p><p><span style="font-size: 1rem;">  MTNL users get two 1Gbps plans, for 2,990 and 4,990. The plans are now restricted to Delhi. </span></p><p><span style="font-size: 1rem;">Jio All-in-one plans start at Rs.222 post introduction of 6ps/min call charges for Jio to non-Jio calls.&nbsp;</span></p>";
</script>
    var htmlFromDatabase = `<?php echo $topic['topicContent']; ?>`
    $("#topicContent").summernote('code', htmlFromDatabase);