1

As you can see below I am trying to call the two functions after my document has loaded, however when I am running the code I get the following error: syntax error unexpected token: <

edit: I added my html code below so you can take a closer look at it. Thanks

this is my index.php file:

<?php
require 'fb-php-sdk/facebook.php';
$app_id = '251156051648844';
$app_secret = 'be37135d238e66ddce8f4ce8db20e668';
$app_namespace = '';
$app_url = 'http://www.paulmeskers.com/rutgers/twenty/canvas/';
$scope = 'email,publish_actions';

// Init the Facebook SDK
$facebook = new Facebook(array(
'appId'  => $app_id,
'secret' => $app_secret,
));

// Get the current user
$user = $facebook->getUser();

// If the user has not installed the app, redirect them to the Auth Dialog
if (!$user) {
$loginUrl = $facebook->getLoginUrl(array(
  'scope' => $scope,
  'redirect_uri' => $app_url,
));

print('<script> top.location.href=\'' . $loginUrl . '\'</script>');
}

if(isset($_REQUEST['request_ids'])) {
  $requestIDs = explode(',' , $_REQUEST['request_ids']);
  foreach($requestIDs as $requestID) {
  try {
    $delete_success = $facebook->api('/' . $requestID, 'DELETE');
   } catch(FacebookAPIException $e) {
    error_log($e);
    }
  }
}



?>

<!DOCTYPE html>

<html>
<head>
<title>Twenty Questions</title>
<meta property="og:title" content="ttt" />
<meta property="og:type" content="activity" />
<meta property="og:url" content="https://apps.facebook.com/251156051648844/" />
</head>
<body id="yo">
<div id="fb-root"></div>
<script src="//connect.facebook.net/en_US/all.js"></script>
<script type='text/javascript' src='jquery-1.7.2.min.js'></script>
<script type='text/javascript' src='ui.js'></script>

<script>
    var appId = '<?php echo $facebook->getAppID() ?>';
    var uid;

    // Initialize the JS SDK
    FB.init({
        appId: appId,
        cookie: true,
    });

    FB.getLoginStatus(function(response){
        uid = response.authResponse.userID ? response.authResponse.userID: null;
    });

function authUser() {
    FB.login(function(response) {
    uid = response.authResponse.userID ? response.authResponse.userID : null;
    }, {scope:'email,publish_actions'});

}


</script>


    <input type="button" id="b1" value="Create Game" onClick="createGame(uid)"/>
<input type="button" id="b2" value="Share this game" onClick="shareOnTimeline()" />
    <input type="button" id="b4" value="fetch created games" onClick="fetch_creator_games(uid)" />
    <input type="button" id="b5" value="fetch joined games" onClick="fetch_joined_games()"/>
    <input type="button" id="b3" value="tewst" onClick="build_creator_ui()" />

    <p><b>Games created by me:</b></p>
    <div id="createdGames" ></div>
    <p>------------------------------------------------------</p>
    <p><b>Games created by others:</b></p>
    <div id="invitedGames" ></div>



</body>
</html>
16
  • 3
    The error looks like it is outside of this code block Commented May 4, 2012 at 0:53
  • Yea it's somewhere else.... do you get a line number when you run it in firefox? Commented May 4, 2012 at 0:54
  • I agree with John, is there any way you could post more code? Commented May 4, 2012 at 0:54
  • Yup. Nuthin' wrong w/the code I see here. Commented May 4, 2012 at 0:55
  • 1
    There has to be more to the JavaScript than this. What is inviterID, and where is it defined? Where are the bodies to these functions? Commented May 4, 2012 at 0:57

2 Answers 2

1

Somewhere during the execution of your page a < character ended up where it shouldn't be. Since you suggested this error was being raised in the jQuery source file, it's likely that you have a selector written incorrectly. Perhaps you were trying to select an HTML element and forgot to wrap it in quotes, or you were trying to create an element.

Keep Your JavaScript Clean

This error could be raised by something that resembles the following:

$(<input>).attr("id", "foo");

Note the selector isn't wrapped in quotes, hence this will raise an error that reads like the one you received.

Check AJAX Responses

I noticed you are expecting JSON to come down the pipe, but after pushing some POSTS off to your server I found that an incorrect userid would result in the following response:

<br/><br/>
<label style='color:red;font-size:200%;'>
  Unable to load guessing games for user_id
</label>
<br/>

This could cause problems. Be sure to send your error messages down as JSON as well.

{ success: 0, message: 'Unable to load guessing games for this user id' }

To construct this JSON string in PHP, you can do the following:

$response = array( 'success' => 0, 'message' => 'Unable to...this user id' );
echo json_encode( $response );

Keep Your Markup Clean

Make sure you have a proper page as well:

<!DOCTYPE html><!-- no whitespace or output before the doctype -->
<html>
  <head>
    <title>Title Here</title>
    <style>
      body { color: red } /* styles in the head */
    </style>
    <script>var scripts_in_the_head_tag = true;</script>
  </head>
  <body>
    <p>HTML goes within the body tags.</p>
    <script>var scripts_in_the_body_tag = true;</script>
  </body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

0

I typically see this error when I make an ajax request that expects a JSON response, but receives HTML instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.