views:

30

answers:

0

I have been playing around with facebook for the past few days and have written a simple app that asks the user a question about a random friend. I am using ajax to change the question and I though I had it working until I tried it in Internet Explorer. Please bare with my code since I am learning :-D

This work perfect in Firefox and Chrome but does not work in Internet Explorer.

<?php   //******SKIP.PHP
    require_once 'facebook/facebook.php';
    require_once 'lib/db.php';

    $appapikey = '';
    $appsecret = '';
    $facebook = new Facebook($appapikey, $appsecret);
    //$user_id = $_POST["uid"];

    $sql = 'SELECT * FROM questions ORDER BY RAND()';
    $result = querydb('1', $sql);

    if (mysql_num_rows($result) > 0)
    {
        $info = mysql_fetch_array($result);
        $friends = $facebook->api_client->fql_query("SELECT uid2 FROM friend 
                 WHERE uid1=1234567" );
        shuffle($friends);
        $randomUser = json_decode(file_get_contents('https://graph.facebook.com/' .
             $friends[0]["uid2"]));
        echo '<img src="https://graph.facebook.com/' . $friends[0]["uid2"] .
              '/picture?type=large" >';
        echo "Do you think " . $randomUser->name . " " . $info['question'];
    }

<?php  //******INDEX.PHP
require_once 'facebook/facebook.php';
require_once 'lib/db.php';

$appapikey = '';
$appsecret = '';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();
?>

<html>
<head>
<script type="text/javascript">
function skipQuestion(userID){
 var ajaxRequest;  // The variable that makes Ajax possible!

 var currentTime = new Date();
 var seconds= currentTime.getSeconds();
 var url = 'skip.php?=' + seconds;

 try{
  // Opera 8.0+, Firefox, Safari
  ajaxRequest = new XMLHttpRequest();
 } catch (e){
  // Internet Explorer Browsers
  try{
   ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try{
    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (e){
    // Something went wrong
    alert("echo :-o");
    return false;
   }
  }
 }
 ajaxRequest.onreadystatechange = function()
 {
  if(ajaxRequest.readyState == 4)
  {
   document.getElementById('stuff').innerHTML = ajaxRequest.responseText;
  }
 }
 ajaxRequest.open("POST", url , true);
 ajaxRequest.send(); 
}

</script>
</head>
<link rel="stylesheet" type="text/css" media="screen" href="http://aafhe8gz.facebook.joyent.us/style.css?v=1.02" />

<body>
<?php

echo '<div id = "main">';
    echo '<div id = "stuff">';
    $sql = 'SELECT * FROM questions ORDER BY RAND() LIMIT 0, 1';
    $result = querydb('1', $sql);
    if (mysql_num_rows($result) > 0)
        $info = mysql_fetch_array($result);

    $friends = $facebook->api_client->fql_query("SELECT uid2 FROM friend WHERE uid1=" . 
          $user_id );
    shuffle($friends);
    $randomUser = json_decode(file_get_contents('https://graph.facebook.com/' .
          $friends[0]["uid2"]));
    echo '<img src="https://graph.facebook.com/' . $friends[0]["uid2"] .
           '/picture?type=large" >';
    echo "Do you think " . $randomUser->name . " " . $info['question'];
    echo '</div>';
    echo '<form id="input"  method="post">';
        echo '<a href="#" onclick="submitForm()">Submit</a>';
 echo ' | ';
 echo '<a href="#" onclick="skipQuestion(' . $user_id . ')">Skip</a>';
    echo '</form>';
echo '</div>';

?>

</body>