0

我擔心這個問題可能有一個簡單的答案,但男孩我努力在 徒勞找到它!任何幫助,將不勝感激。我們已經將我們的Facebook應用程序 設置得很好,我們的操作和對象使用一個小腳本Java 工作得很好。但是...我想簡化我們網站的整個流程,通過在JavaScript中觸發動作的警告對話框中的 。簡化Facebook API腳本中的IF/ELSE

這就是我們現在已經有(工作):

<script type="text/javascript"> 
function postResonate_with_cambodia() 
{ 
    FB.api('/me/onemandala:resonate_with' + 
      '?intention=http://1mandala.org/1action-002','post ', 
      function(response) { 
      if (!response || response.error) { 
      if (confirm('You are not yet signed up for 1Mandala. 1Mandala uses Facebook Connect to  showcase the amazing 1Actions folks are taking on our platform. We will redirect you now to the signup page...')) { window.location.href='http://www.1mandala.org/app-signup ' } else { void('') };; 
      } else { 
      if (confirm('You are resonating with the intention for 1SewingKit Cambodian Orphanage Empowerment. We will take you now to the project page to take action...')) { window.location.href='http://1mandala.org/1action-002 ' } else { void('') };; 
      } 
      }); 
} 
</script> 

的對話應該使它很清楚,應該是如何工作的。 但是,如果不是那些對話, 的腳本會將訪問者直接發送到Facebook註冊會話或 登錄頁面,這會不會更好?這是我的嘗試,不起作用。 :-(任何建議將 不勝感激。

<script type="text/javascript"> 
function postResonate_with_cambodia() 
{ 
FB.api('/me/onemandala:resonate_with' + 
'?intention=http://1mandala.org/1action-002','post', 
function(response) { 
if (!response || response.error) 
{window.location.href='http://www.sign-up-page.com' } ; 
} else { 
{ window.location.href='http://1mandala.org/app-1action-002' } ; 
} 
}); 
} 
</script> 
+2

請定義「不起作用」。它做什麼或不做什麼?你有什麼錯誤嗎?你正在檢查瀏覽器的控制檯嗎? – deceze

+0

謝謝,很好的問題。我在Firefox調試器上得到的錯誤是「ReferenceError:postResonate_with_cambodia未定義@ http://1mandala.org/app:1」 – russs

回答

1

這很簡單,你有一個語法錯誤。這對ReferenceError: postResonate_with_cambodia is not defined的原因,但語法問題應該已經被報道過。

你有太多的閉合括號(或者開口太少);你也不需要把你的身體分成兩個部分,一個就足夠了,而且對於一個單線你甚至不需要校正:

function postResonate_with_cambodia() { 
    var url = '/me/onemandala:resonate_with?intention=http://1mandala.org/1action-002'; 
    FB.api(url, 'post', function(response) { 
     if (!response || response.error) { 
      window.location.href='http://www.sign-up-page.com'; 
     } else { 
      window.location.href='http://1mandala.org/app-1action-002'; 
     } 
    }); 
} 

總是縮進你的代碼。在單個語句之後使用分號,而不是在塊之後使用。

+0

WOW!而已!我有一種感覺,這與簡單的語法監督有關。非常感謝你的糾正。現在修改後的腳本從我們網站的流程中取出1步或3步。希望這可以幫助其他人簡化Open Graph操作的使用。正如史蒂夫喬布斯所說:「簡單是複雜性的最高形式」。再次感謝! ---腳本在這裏運行:www.1mandala.org/app – russs