0

이 질문에 대한 답은 간단 할 수도 있지만, 소년은 내가 멍청이 에 수고를했습니다! 어떤 도움을 주시면 감사하겠습니다. 우리는 페이스 북의 애플 모든 좋은 설정하고 우리의 행동과 객체는 작은 자바 스크립트와 함께 잘 작동합니다. 그러나 ... 나는 행동을 유발하는 자바 스크립트의 경고 대화 상자에서 을 제거하여 사이트 전체의 흐름을 간소화하고 싶습니다.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 Actions를 사용하는 것을 단순하게 해줄 수 있기를 바랍니다. 스티브 잡스 (Steve Jobs)는 "단순함은 최고 수준의 세련미"라고 말합니다. 다시 한 번 감사드립니다! --- www.1mandala.org/app 스크립트가 작동 중입니다. – russs