2012-02-29 70 views
0

我有一個Facebook應用程序,在所有其他瀏覽器,但IE瀏覽器。這裏是我的javascript代碼:與IE9的AJAX問題

(function(d){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 


    window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : '123456789', // App ID 
     channelUrl : 'http://test/channel.php', // Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true, // parse XFBML 
     oauth  : true // turn on oauth 
    }); 

    // Additional initialization code here 
    }; 


function start() { 
    //send initial AJAX request 
    var bike_var = $("select#bike").val(); 
    var reason_var = $("textarea#reason").val(); 
    var dataString = 'bike='+ bike_var + '&reason=' + reason_var; 

    $.ajax({ 
     type: "POST", 
     url: "save.php", 
     data: dataString, 
     success: function(data) { 
     //set ID in the form 
     $("input#recordID").val(data); 
     doLogin(); 
     } 
    }); 
} 

    function doLogin() { 
    //Do request to Facebook to get user details and then post to wall and the submit the form 
    FB.login(function(response) { 
     if (response.authResponse) { 
      getUserInfo(); 
     } else { 
     alert("Sorry! We can't enter you into the competition unless you allow our Facebook app!"); 
     } 
    }, {scope: 'email, publish_stream'}); 
    } 

    function getUserInfo() { 
     FB.api('/me', function(info) { 
     $("input#name").val(info.name); 
     $("input#email").val(info.email); 
     $("input#FID").val(info.id); 


      var params = {}; 
      params['message'] = $("textarea#reason").val(); 
      params['name'] = 'Test'; 
      params['description'] = ''; 
      params['link'] = 'http://www.facebook.com/ChainReactionCycles'; 
      params['picture'] = 'http://crc.test/img/logo.gif'; 
      params['caption'] = 'Test'; 
      postToWall(params); 
    }); 
    } 

    function postToWall(param) { 
     FB.api('/me/feed', 'post', param, function(wall) { 
       if (!wall || wall.error) { 
       } else { 
      document.forms["comp-entry"].submit(); 
       } 
     }); 
    } 

這裏是我的提交按鈕,揭開序幕的代碼,目前在所有其他瀏覽器中工作代碼:

<input type="submit" name="submit_button" value="Enter Competition" onclick="start(); return false;"> 

在IE中,這只是去到一個空白頁與新記錄的記錄ID,但在我的數據庫中沒有填寫所需的Facebook字段。當我調試時IE中的錯誤是'SCRIPT5002:Function expected'。如果任何人有任何想法,我會永遠感謝

+0

是否在調用save.php之前或之後發生空白屏幕? – DMCS 2012-02-29 22:24:56

+0

它發生在 – user1240615 2012-03-01 09:13:11

回答

2

我有我的腳本和谷歌搜索錯誤代碼相同的錯誤信息,所以我意外地偶然發現你的問題。你的代碼行,踢錯誤幫助我,所以我可以幫你現在。

顯然,IE 9不喜歡「開始」作爲函數名稱。我在我的代碼中有相同的功能,當我發現我自己的代碼和你的代碼之間有冗餘時,我替換了函數名稱et voila,現在一切正常。

+0

之後不要害怕大寫字母:P – Lix 2012-07-29 12:14:30