我想,当用户presses Facebook的Like按钮来更新数据库字段。
I want to update a database field when a user presses the Facebook Like button.
一个小片断低于我的code。我已经简化了,所以PLZ不启动有关的错误/不良行为;)
A small snippet of my code below. I've simplified it, so plz don't start about the errors/bad practices ;)
<?php
function updateLike () {
mysql_query("UPDATE like SET liked = '1'");
}
?>
<script>
FB.Event.subscribe('edge.create', function(response) {
<?php updateLike() ?>
});
</script>
所以,这是行不通的。我读过一些关于做一个AJAX调用,但我无法找到一个很好的例子,我的情况。
So, that doesn't work. I've read something about making an AJAX call but I couldn't find a good example for my situation.
谁可以把我在正确的方向?
Who can push me in the right direction?
是的,你可以更新数据库使用 AJAX
Yes, you can update db using ajax
剧本
FB.Event.subscribe('edge.create', function(response) {
// ajax call
$.post('server.php', function(data) {
});
});
server.php
server.php
您可以做更新或任何服务器进程
You can do update or whatever the server process
mysql_query("UPDATE like SET liked = '1'");
您可以轻松地使用jQuery容易使得Ajax调用。
You can get easy make ajax call easily using jQuery.