我需要这个功能:使用Facebook登录的用户登录。只要用户连接,一些Facebook数据需要使用POST方法发送,所以另一个页面(setSes.php)可以处理数据。如何使用POST方法在jQuery中发送数据?
我已经创建了下面的代码,(添加了一个额外的警报,看看数据是否应该加载,它工作得很好),但不知何故页面setSes.php没有被调用。
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";
?>
'型=“POST”'会做的伎俩。删除你的'方法' –
nope,不幸没有工作:( –
然后去与$ .post https://api.jquery.com/jquery.post/ –