【发布时间】:2011-07-26 09:55:46
【问题描述】:
我想跟踪人们何时点击我网站上的 Facebook“赞”按钮。
我有一个小脚本设置,但它似乎不起作用,我不知道它可能是什么。有什么建议么? AppID 是正确的,此脚本仅用于测试,所以不要介意缺少验证:
index.html
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>FB Like Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
$(document).ready(function() {
window.fbAsyncInit = function() {
FB.init({appId: 'x', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('edge.create', function(href, widget) {
$.ajax({
type: 'POST',
url: 'like-sql.php',
data: ({liked : 1})
});
});
FB.Event.subscribe('edge.remove', function(response) {
$.ajax({
type: 'POST',
url: 'like-sql.php',
data: ({liked : 0})
});
});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = 'http://connect.facebook.net/nl_NL/all.js#appId=x&xfbml=1';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
});
</script>
<fb:like href="http://x.x.x" layout="button_count" show_faces="true" width="500"></fb:like>
</body>
</html>
like-sql.php
<?php
$status = $_POST['liked'];
mysql_query("UPDATE `fb_like` SET umk_like = $status WHERE user_id = '3432'");
?>
我是整个 jQuery ajax 的新手,所以我真的不知道应该如何调试它。欢迎任何建议:)
编辑:没关系,伙计们,我明白了。
我正在一个外部文件中对此进行测试,默认情况下我没有包含 jQuery ;) 我不敢相信我花了这么长时间才弄明白,哈哈。无论如何感谢所有的帮助!
【问题讨论】:
-
@sascha: 是的,我已经用总代码更新了 index.html
-
@gowri:这实际上是一个不同的问题,我希望它被注意到。
-
尝试在你的ajax调用中加入success:function(data)和error:function(jqXHR, textStatus, errorThrown) 然后你可以提醒这些变量,看看发生了什么
-
@tommy:我尝试了以下操作:
success : function(data) { alert(data); }, error : function(jqXHR, textStatus, errorThrown) { alert(data); },但没有任何警报。甚至在提醒某些文本时也不会。