2012-06-04 41 views
0
在牆壁上出現未知錯誤的JavaScript FB圖形API發佈

我正在使用FB圖形API我的功能張貼在牆上的user`s牆上張貼Facebook的整合情況如下:與在Firefox

function PostToWall() 
{ 

     var mymessage = 'my message'; 
     var mypic = 'http://myapp/a.jpg'; 
     var mylink = 'http://www.myapp.com'; 
     var myname = 'myApp'; 
     var mydesc = 'my desc .'; 
     FB.api('/me/feed', 'post', { message: mymessage, picture: mypic, link: mylink, name: myname, description: mydesc }, function (response) { 
      if (!response || response.error) { 
         alert(response.error.message); 
      } else { 
         alert('Post ID: ' + response.id); 
      } 
     }); 
     // alert('Do you want to continue ? '); 
}; 

它工作在克羅默正常,但當我用同樣的在Firefox從alert(response.error.message);提示未知錯誤。而在Firefox錯誤的錯誤控制檯

Error: uncaught exception: [Exception... "prompt aborted by user" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: resource://gre/components/nsPrompter.js :: openTabPrompt :: line 468" data: no] 

我找到了解決辦法我s提示用戶在函數結束前查看最後一行alert('你想繼續嗎? 「);。當我寫這個警報時,它也可以在Firefox中正常工作,但我不想提示用戶輸入任何消息。可能是什麼問題,解決方案是什麼?

我正在使用firefox 5.0。我的操作系統是Windows 7

PostOnWall功能是從另一個功能是如下叫:

function f(){ 

    PostToWall(); 
    ... 
    ... 
    //code to click a submit button 
} 
+1

您是否嘗試過使用Firebug的回調打破,看看拋出異常?我想問題在於你在調用PostToWall(如重定向瀏覽器等)後立即做了一些事情,這會觸發錯誤 –

+0

,可能是因爲我登錄到我的網站時發佈在用戶的牆上。我必須這樣做,那麼解決方案是什麼?它適用於谷歌瀏覽器。 –

+1

簡單,只需將PostToWall後面的代碼移動到FB.api回調處理程序即可。 –

回答

3

我已經寫代碼,單擊回調處理程序提交按鈕如下:

function PostToWallCallBackHandler(response) { 
    if (!response || response.error) { 
     alert(response.error.message); 
    } else { 
      document.getElementById('fbSubmit').click(); 
    } 
} 
function PostToWall(mymessage,mypic,mylink,myname,mydesc,callbackHandler) { 
    FB.api('/me/feed', 'post', { message: mymessage, picture: mypic, link: mylink, name: myname, description: mydesc },function (response){callbackHandler(response);}); 
}; 

它正常工作與兩個克羅默和Firefox,Safari和IE 9