1
當我嘗試使用JavaScript SDK刪除應用程序請求時,它向FireBug返回一個錯誤對象,內容如下:「load-error:unknown」。嘗試刪除Javascript SDK中的apprequest時出現'load-error:unknown'
這是一個同時使用PHP和JS SDK的測試應用程序。
<?php
// This loads the PHP SDK and pulls a user's apprequests
require 'fb-sdk/facebook.php';
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
$user_requests = $facebook->api('/me/apprequests');
$apprequests = $user_requests['data'];
} catch (FacebookApiException $e) {
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
$user = null;
}
}
?>
// This spits out a table of requests with links to delete them.
// The table doesn't reload when you delete a request so you have to refresh.
<table>
<?php foreach ($apprequests as $apprequest) { ?>
<tr>
<td><a href="" onClick="deleteRequest('<?php echo $apprequest['id']; ?>')">Delete</a></td>
</tr>
<?php } ?>
</table>
// This loads the JS SDK and makes a function to delete requests.
<script>
function deleteRequest(requestId) {
FB.api('/' . requestId, 'delete', function (response) {
console.log(response);
// Will have a function to reload the table...
});
}
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $facebook->getAppID() ?>',
cookie: true,
xfbml: true,
oauth: true
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
我知道deleteRequest的作品,因爲我可以用這份表單手動刪除請求:
<input type="text" name="manReqId"></text>
<input type="button"
onClick="manDelRequest(); return false;"
value="Delete request"
/>
<script>
function manDelRequest() {
deleteRequest(document.getElementsByName("manReqId")[0].value);
}
</script>
此方法返回「真」到螢火蟲。
我假設我寫onClick值的方式有問題。有人能幫我嗎?
標籤是問題所在。如果我將它變成標籤或甚至標籤,則onClick將起作用。 – 2012-04-09 08:48:20
將標記的href值從「」更改爲「#」解決了此問題。 – 2012-04-09 09:44:44