2016-10-03 208 views
2
<a href="javascript:void(0)" onclick="return fblogin();" class="wksocialsignup fb_button_ps"><img src="<?php echo $this->helper('socialsignup/active')->getLoginImg()?>" alt="<?php echo $this->__('Facebook')?>" title="<?php echo $this->__('Connect with Facebook')?>"/></a> 

我在登錄和結帳頁面都使用相同的代碼。 Facebook登錄工作在登錄頁面正常,但當我嘗試在結帳相同的登錄它給我像使用Facebook登錄登錄無法在結帳登錄頁面上工作,但在登錄頁面上工作

Uncaught ReferenceError: fblogin is not defined

錯誤可能是什麼問題,並沒有關於如何解決它有什麼建議?

+0

檢查包含函數fblogin()的腳本是否正確加載。 –

回答

2

我得到了一個答案,我忘了加載下面的腳本在結帳頁面調用fblogin()。

<script language="JavaScript" type="text/javascript"> 
/*<![CDATA[*/ 
window.fbAsyncInit = function() { 
    FB.init({appId: '<?php echo $this->getAppId()?>',    
     status  : true, 
      cookie  : true, 
      xfbml  : true, 
      oauth  : true}); 

    FB.getLoginStatus(function(response) { 
     if (response.status == 'connected') { 
     <?php if (Mage::getSingleton('customer/session')->isLoggedIn() && $uid = $this->checkFbUser()):?> 
      greet('<?php echo $uid?>'); 
     <?php endif?> 
     } 
    }); 
}; 
(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/<?php echo Mage::app()->getLocale()->getLocaleCode()?>/all.js"; 
      d.getElementsByTagName('head')[0].appendChild(js); 
     }(document)); 

function login(){ 
     document.location.href="<?php echo $this->getUrl('socialsignup/facebook/login')?>?referer=<?php echo Mage::helper('core')->urlEncode($this->helper('core/url')->getCurrentUrl())?>"; 
    } 
    function logout(){ 
     document.location.href="<?php echo $this->getUrl('socialsignup/facebook/logout')?>"; 
    } 
    function greet(id){ 
     FB.api('/me', function(response) { 
     var src = 'https://graph.facebook.com/'+id+'/picture'; 
     $$('.welcome-msg')[0].insert('<img height="20" src="'+src+'"/>'); 
     }); 
    } 

    function fblogin(){ 
     FB.login(function(response) { 

      if (response.status == 'connected') { 
       login(); 
      } else { 
       // user is not logged in 
       window.location.reload(); 
      } 
     }, {scope:'email,publish_actions'}); 
     return false; 
    } 
/*]]>*/ 
</script> 

現在它的工作正常。