衫裤跑路 2012-02-29 15:42 采纳率: 50%
浏览 35

IE9的AJAX问题

I have a facebook app that works in all other browsers but IE. Here is my javascript code:

(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();
          }
        });
  }

Here is code for my submit button that kicks off the code, currently working in all other browsers:

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

In IE, this just goes to a blank page with the record ID of the new record, but in my database none of the required facebook fields are filled. The error in IE when i debug is 'SCRIPT5002: Function expected'. If anyone has any ideas i would be eternally grateful

  • 写回答

1条回答 默认 最新

  • weixin_33709219 2012-07-29 12:07
    关注

    I had the same error message on my script and googled for that error code, so I accidently stumbled across your question. your line of code, that kicks the error helped me, so I can help you now.

    Obviously IE 9 does not like "start" as a function name. I had the same function in my code, and after I found that redundancy between my own code and yours, I replaced the function name, et voila, everything works fine now.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题