2013-01-24 46 views
-1

我的问题是如下:Facebook上的JavaScript像按钮(XML,XFBML)

时,我会加载一个网站的XML标签(见下文),在使用Ajax加载页面会它不会显示。

table2.php页面将在下面的div中加载Ajax:<div id="update_div"></div>,但不会显示。

这是我的标签将用于打印像按钮等:<fb:like href="http://website_url.nl" send="true" layout="button_count" width="450" show_faces="false"></fb:like>

我不能找到这个问题的任何解决方案,并希望有人能帮助白衣TIS问题。

我的页面代码屁股如下:

的index.php

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#" > 
    <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script> 
    <script type="text/javascript" src="/js/jquery.js"></script> 
    <head> 
    <script type="text/javascript"> 
    $.setDivContentAjax = function(){   
      var url = window.location.hash.replace("#", ""); 
      var paramaters = null; 
      try 
      { 
       var parameters = JSON.parse('{"' + decodeURI(url.replace(/&/g, "\",\"").replace(/=/g,"\":\"")) + '"}'); 
       //console.log(parameters); 
      } 
      catch(error) 
      { 
      } 

      targetdiv = $('#update_div'); 

      targetdiv.hide(); 
      $('#loading-image').show(); 

      $.ajax({ 
       url: '/includes/table2.php', 
       context: targetdiv, 
       type: "GET", 
       timeout:18000, 
       data: parameters, 
       success: function(data) { 
       window.setTimeout(function() {$('#loading-image').hide(); targetdiv.html(data); targetdiv.show();} ,300); 
       } 

      });  
     } 

     $(document).ready(function() 
     { 
      $.setDivContentAjax(); 

      $(window).bind('hashchange', function() { 
       $.setDivContentAjax(); 
      }); 
     }); 
    </script> 
    </head> 
    <body> 
     <div id="loading-image" style="display:none; padding: 50px 0 50px 0; text-align: center;"><img src="/img/ajax-loader-circle.gif"></div> 
    <div id="javascript" style="display:none;"></div> 
    <div id="update_div"></div> 
    </body> 
</html> 

table2.php

<script> 
    (function(d, s, id) { 
     var js, fjs = d.getElementsByTagName(s)[0]; 
    if (d.getElementById(id)) return; 
     js = d.createElement(s); js.id = id; 
     js.src = "//connect.facebook.net/nl_NL/all.js#xfbml=1&appId=APP_ID"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk')); 
</script> 
<fb:like href="http://website_url.nl" send="true" layout="button_count" width="450" show_faces="false"></fb:like> 
+0

_“我不能找到这个问题的任何解决方案” _ - 右边,只讨论轻车熟路...... https://developers.facebook.com/docs/reference/javascript /FB.XFBML.parse/ – CBroe

+0

这将起作用,但ajax没有刷新页面来解析xml。我的页面无法重新加载时如何加载解析器? –

回答

0
The solution: 

<script> 
    success: function(data) { 
    $('#loading-image').hide(); 
    targetdiv.html(data); 
    targetdiv.show(); 
    FB.XFBML.parse(); 
    } 
</script>