SQL query in FB JavaScript
I want to update a database field w开发者_StackOverflow中文版hen a user presses the Facebook Like button.
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>
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?
Yes, you can update db using ajax
Script
FB.Event.subscribe('edge.create', function(response) {
// ajax call
$.post('server.php', function(data) {
});
});
server.php
You can do update or whatever the server process
mysql_query("UPDATE like SET liked = '1'");
You can get easy make ajax call easily using jQuery.
Check out this blog post, it has good examples for the latest JS SDK http://thinkdiff.net/facebook/new-javascript-sdk-oauth-2-0-based-fbconnect-tutorial/
精彩评论