1

正如您在下面看到的,我试图在我的文档加载后调用这两个函数,但是当我运行代码时,我收到以下错误:syntax error unexpected token: <

编辑:我在下面添加了我的 html 代码,以便您仔细查看。谢谢

这是我的 index.php 文件:

<?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>
4

2 回答 2

1

在页面执行期间的某个地方,一个<角色最终出现在不应该出现的地方。由于您建议在 jQuery 源文件中引发此错误,因此很可能您的选择器编写不正确。也许您正试图选择一个 HTML 元素而忘记用引号括起来,或者您正试图创建一个元素。

保持你的 JavaScript 干净

类似于以下内容的内容可能会引发此错误:

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

请注意,选择器没有用引号括起来,因此这会引发一个错误,类似于您收到的错误。

检查 AJAX 响应

我注意到您希望 JSON 能够顺利通过管道,但是在将一些 POSTS 推送到您的服务器后,我发现错误的用户 ID 会导致以下响应:

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

这可能会导致问题。请务必将错误消息也以 JSON 格式发送。

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

要在 PHP 中构造这个 JSON 字符串,您可以执行以下操作:

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

保持标记干净

确保您也有正确的页面:

<!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>
于 2012-05-04T00:59:55.323 回答
0

当我发出一个期望 JSON 响应但接收 HTML 的 ajax 请求时,我通常会看到此错误。

于 2012-05-04T01:00:19.657 回答