AJAX与IE9有关

时间:2012-02-29 15:42:20

标签: ajax facebook

我有一个Facebook应用程序,适用于所有其他浏览器,但IE。这是我的javascript代码:

(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:功能预期'。如果有人有任何想法我会永远感激

1 个答案:

答案 0 :(得分:2)

我的脚本上有相同的错误消息,并使用Google搜索该错误代码,因此我无意中偶然发现了您的问题。您的代码行,启动错误帮助了我,所以我现在可以帮助

显然IE 9不喜欢“start”作为函数名。我的代码中有相同的功能,在我发现自己的代码与你的代码之间存在冗余后,我替换了函数名称​​ et voila ,现在一切正常。

相关问题