Facebook喜欢按钮没有在第一次请求时显示

时间:2012-06-08 19:18:25

标签: facebook asp.net-mvc-3 jquery-mobile facebook-like

我在asp.net mvc3中有视图,其中包含产品列表,当用户点击产品时,用户转到另一个包含产品详细信息的视图,问题是当页面完成时,facebook like按钮没有显示加载。但是,如果我刷新页面,那么它会显示,google plus +1按钮正常工作。帮助PLZ。

<!DOCTYPE html>
<html>
    <head>
         <meta charset="utf-8" />
         <meta name="viewport" content="initial-scale=1.0, width=device-width, height=device-height,user-scalable=no" />
         <title>xxxxxxxx</title>
         <link href="/Content/Site.css" rel="stylesheet" type="text/css" />
         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"> </script>
         <link href="/Content/JqueryContent/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css" />
         <script src="/Content/JqueryContent/jquery.ui.core.js.js" type="text/javascript"></script> 
         <script src="/Content/JqueryContent/jquery.ui.widget.js.js" type="text/javascript"></script>
         <script src="/Content/JqueryContent/jquery.ui.position.js" type="text/javascript"></script>
         <script src="/Content/JqueryContent/jquery.ui.autocomplete.js" type="text/javascript"></script>
         <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
         <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js" type="text/javascript"> </script>
    </head>
    <body>
    <div id="fb-root"></div>
    <script type="text/javascript">
            window.fbAsyncInit = function() {
              FB.init({
                appId      : 'xxxxxxxxxxxx',
                status     : true, 
                cookie     : true,
                xfbml      : true,
                oauth      : true,
              });
              FB.Event.subscribe('auth.statusChange', handleStatusChange);
            };

            (function(d){
               var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
               js = d.createElement('script'); js.id = id; js.async = true;
               js.src = "//connect.facebook.net/en_US/all.js";
               d.getElementsByTagName('head')[0].appendChild(js);
             }(document));
    </script>
    <header data-role="header" data-theme="a"><h3>xxxxx</h3></header>
    <div data-role="content">
    <div class="fb-like" data-send="true" data-width="450" data-show-faces="true"></div>
    <style>.fb_edge_comment_widget {display: none !important; }</style> 
    <div class="g-plusone" data-size="medium"></div>
    <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>    
    </div>
    <footer data-role="footer" data-theme="a" style="font-family:Trebuchet MS;"><h5></h5></footer>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您可能想要更新FB sdk代码段。我刚刚检查了Facebook Javascript SDK页面,它就是这样做的:

// Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

注意插入js的新方法insertBefore()。也许这会有所帮助。

干杯!