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

问题描述 投票:0回答:1

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

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

<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.2"></script>

<div class="w-container">
    <div id="allPosts">
        @foreach (var post in ViewBag.Posts.Data)
        {
            <div class="w-row">
                <div class="w-col w-col-12 w-col-medium-12 w-col-small-12">
                    <p>@post.MetaDescription ...</p>
                </div>
            </div>
            <div class="w-row post-button">
                <div class="w-col w-col-3 w-col-small-12">
                    <input type="hidden" class="postBodyHtmlHidden" value="@post.Body" />
                    <input type="hidden" class="postSlug" value="@post.Slug" />
                    <div class="fb-comments" style="display: none;" data-href="http://localhost:36998/blog#@post.Slug" data-numposts="5"></div>
                    <input type="button" value="Continue Reading" class="btn btn-primary continue-reading-btn" />
                </div>
            </div>
        }
    </div>

    <div id="postBody" style="display:none;">
        <div class="w-row">
            <div class="w-col w-col-12">
                <input type="button" value="Back" onclick="AllPosts()" class="btn btn-primary" />
                <br />
                <div id="postHmtlDiv">

                </div>
                <div id="postCommentDiv">

                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $('.continue-reading-btn').on("click", function () {
        var postHtml = $(this).closest('.w-row').find('.postBodyHtmlHidden').val();
        var postSlug = $(this).closest('.w-row').find('.postSlug').val();
        var postComment = $(this).closest('.w-row').find('.fb-comments').html();

        $('#allPosts').css("display", "none");
        $("#postHmtlDiv").html(postHtml);
        $('#postCommentDiv').html(postComment);
        $('#postCommentDiv .fb-comments').removeAttr('style');
        $("#postBody").fadeIn("slow");

    });

    function AllPosts() {
        $('#postBody').css('display', 'none');
        $('#postHmtlDiv').html('');
        $('#allPosts').fadeIn('slow');
    };

</script>

我不知道如何调试这个。

错误看起来像这样(再次,添加评论后):

enter image description here

javascript asp.net-mvc facebook-javascript-sdk facebook-comments
1个回答
1
投票

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

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

data-href属性不能是localhost。我把它换成别的东西,它有效!

© www.soinside.com 2019 - 2024. All rights reserved.