html页面代码:
WB2.anyWhere(function (W) {
W.widget.connectButton({
id: "wb_connect_btn",
type: '3,2',
callback: {
login: function (o) { //登录后的回调函数
//alert("login: " + o.screen_name) location screen_name id
var ajax = new XMLHttpRequest();
ajax.onreadystatechange=function(){
if (ajax.readyState==4){
//接收数据
alert(ajax.responseText);
//history.go(0);
//document.getElementById("sppwd").innerHTML = ajax.responseText;
}
}
//与服务器建立连接
ajax.open("get","sinaadd.php?oid="+o.id+"&screen_name="+o.screen_name+"&location="+o.location);
//处理请求
ajax.send(null);
},
logout: function () { //退出后的回调函数
alert('logout');
}
}
});
});
php页面代码:
$uid=$_GET['oid'];
$screen_name=$_GET['screen_name'];
$location=$_GET['location'];
$db = new PDO("mysql:host=blog.bwphp.cn;dbname=wangbao","wangbao", "1234",array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'utf8\''));
$db->query("set names utf8");
$addsql = "insert into sina_oauth(uid,screen_name,location) values('$uid','$screen_name','$location')";
$add = $db->exec($addsql);
if($add){
echo "用户信息以成功入库";
}else{
$db->errorInfo();
}
?>