I need to have this function: an user login using Facebook login. As soon as the user's connected, some Facebook data needs to be sent using the POST method, so another page (setSes.php) can handle the data.
I've created the code below, (added an extra alert to see if the data is loaded as it should, which works just fine), but somehow the page setSes.php is not getting called.
function login() {
FB.login(function(response) {
if (response.status === 'connected') {
document.getElementById('status').innerHTML = 'Connected';
FB.api('/me', 'GET', {fields: 'first_name,last_name,name,id,link,gender,locale,picture.width(9999).height(9999)'}, function(response) {
var id=response.id;
var firstName=response.first_name;
var lastName=response.last_name;
var picture=response.picture.data.url;
alert("Selected ID= "+id);
$.ajax({
url:"/setSes.php ",
method:"POST",
data:{
UID: "id",
firstName: "firstName",
lastName: "lastName",
picture: "picture"
}
});
});
} else if (response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'Not connected';
} else {
document.getElementById('status').innerHTML = 'Not able to login';
}
}, {scope: 'email'});
}
setSes.php
<?
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
sec_session_start();
$stmt = $mysqli->prepare("INSERT INTO users(first_name, last_name, oauth_uid, picture
) VALUES (?, ?, ?, ?)");
$stmt->bind_param('ssss', $_POST["firstName"], $_POST["lastName"], $_POST["UID"], $_POST["picture"]);
$stmt->execute();
$stmt->close();
echo "I ran";
?>
type="post"will do the trick. remove yourmethodtypeisan alias for method. You should use type if you're using versions of jQuery prior to 1.9.0.