创建评论时,Facebook评论插件返回500错误

时间:2019-04-15 16:45:15

标签: javascript asp.net-mvc facebook-javascript-sdk facebook-comments

我在MVC环境中使用Facebook评论插件,当我添加评论时,控制台崩溃并显示500错误。页面加载期间加载所有注释时,我出现错误。但是,注释已成功添加到URL ,因此在创建创建内容后发生错误。

这里的相关代码,已尽可能地清理(底部的JavaScript)

buttons: [
{
    extend: 'excel', 
    customize: function (xlsx) {

                        //Apply styles, Center alignment of text and making it bold.

                        var sSh = xlsx.xl['styles.xml'];

                        var lastXfIndex = $('cellXfs xf', sSh).length - 1;



                        var n1 = '<numFmt formatCode="##0.0000%" numFmtId="300"/>';

                        var s2 = '<xf numFmtId="0" fontId="2" fillId="0" borderId="0" applyFont="1" applyFill="0" applyBorder="0" xfId="0" applyAlignment="1">' +

                            '<alignment horizontal="center"/></xf>';

                            '<alignment horizontal="center"/></xf>';

                        sSh.childNodes[0].childNodes[0].innerHTML += n1;

                        sSh.childNodes[0].childNodes[5].innerHTML += s2;



                        var greyBoldCentered = lastXfIndex + 1;



                        //Merge cells as per the table's colspan

                        var sheet = xlsx.xl.worksheets['sheet1.xml'];

                        var dt = $('#tblReport').DataTable();

                        var frColSpan = $(dt.table().header()).find('th:nth-child(1)').prop('colspan');

                        var srColSpan = $(dt.table().header()).find('th:nth-child(2)').prop('colspan');

                        var columnToStart = 2;



                        var mergeCells = $('mergeCells', sheet);

                        mergeCells[0].appendChild(_createNode(sheet, 'mergeCell', {

                            attr: {

                                ref: 'A1:' + toColumnName(frColSpan) + '1'

                            }

                        }));

                        mergeCells.attr('count', mergeCells.attr('count') + 1);



                        var columnToStart = 2;

                        while (columnToStart <= frColSpan) {

                            mergeCells[0].appendChild(_createNode(sheet, 'mergeCell', {

                                attr: {

                                    ref: toColumnName(columnToStart) + '2:' + toColumnName((columnToStart - 1) + srColSpan) + '2'

                                }

                            }));

                            columnToStart = columnToStart + srColSpan;

                            mergeCells.attr('count', mergeCells.attr('count') + 1);

                        }



                        //Text alignment to center and apply bold

                        $('row:nth-child(1) c:nth-child(1)', sheet).attr('s', greyBoldCentered);

                        for (i = 0; i < frColSpan; i++) {

                            $('row:nth-child(2) c:nth-child(' + i + ')', sheet).attr('s', greyBoldCentered);

                        }



                        function _createNode(doc, nodeName, opts) {

                            var tempNode = doc.createElement(nodeName);



                            if (opts) {

                                if (opts.attr) {

                                    $(tempNode).attr(opts.attr);

                                }



                                if (opts.children) {

                                    $.each(opts.children, function (key, value) {

                                        tempNode.appendChild(value);

                                    });

                                }



                                if (opts.text !== null && opts.text !== undefined) {

                                    tempNode.appendChild(doc.createTextNode(opts.text));

                                }

                            }



                            return tempNode;

                        }



                        //Function to fetch the cell name

                        function toColumnName(num) {

                            for (var ret = '', a = 1, b = 26; (num -= a) >= 0; a = b, b *= 26) {

                                ret = String.fromCharCode(parseInt((num % b) / a) + 65) + ret;

                            }

                            return ret;

                        }



                    }
}
]

我不知道该如何调试。

错误看起来像这样(同样,添加注释后也这样):

enter image description here

1 个答案:

答案 0 :(得分:1)

答案很简单!该代码无效!

<div class="fb-comments" style="display: none;" data-href="http://localhost:36998/blog#@post.Slug" data-numposts="5"></div>

data-href属性  不能是localhost。我将其更改为其他内容,并且有效!