1

以下に示すように、ドキュメントが読み込まれた後に 2 つの関数を呼び出そうとしていますが、コードを実行すると次のエラーが発生します。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 応答を期待する ajax 要求を作成し、代わりに HTML を受け取ると、このエラーが表示されます。

于 2012-05-04T01:00:19.657 に答える