save facebook user details to database
I have a login to facebook button and all works well, on click i would like the users id, first and last name to be added to a database (i have a php file for this which works nicely) The problem i have is posting the data to the php file. My code is below an开发者_运维百科d i get the error $ is not defined. I understand that i will need to reference the jquery file. However i don't know where to as the script already references facebooks js file
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'137558232981530',
cookie:true,
status:true,
xfbml:true
});
FB.Event.subscribe('auth.login', function(response)
{
FB.api('/me', function(response) {
$.post("usersignup.php", {
facebookid: response.id,
email: response.email,
firstname: response.first_name,
lastname: response.last_name
});
});
});
</script>
1.You have to reference jQuery above your script (anywhere above, reference order does not matter for independent scripts(that does not conflict with each other)) e.g.
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script src="jquery.js"></script>
2.Try using jQuery.post instead of $.post as the '$' can conflict with other script APIs (like prototype). jQuery conflicts with other frameworks
精彩评论