本帖最后由 HelpMe 于 2012-7-19 18:04 编辑
利用ajax传递数据到 CI控制器 SaveInfo/save_qq_openId 下
JS复制代码 var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
/*QQ 登录*/
if(QC.Login.check())
{
QC.Login.getMe(function(openId, accessToken){
xmlhttp.open("GET","http://localhost/CI/index.php/SaveInfo/save_qq_openId? openId="+openId+"&accessToken="+accessToken,true);
xmlhttp.send();
});
}
复制代码
在SaveInfo/save_qq_openId内,设置SESSION
PHP复制代码
function save_qq_openId()
{
$openId = $this->input->get('openId');
$accessToken = $this->input->get('accessToken');
//echo $openId;
//echo $accessToken;
$_SESSION['openId'] = $openId;
复制代码
已经在首页<html>标签前,加了<?php session_start()?>,在另个控制器获取SESSION变量失败,
A PHP Error was encounteredSeverity: Notice Message: Undefined index: openId Filename: controllers/ShopOnSale.php Line Number: 125
万分疑惑 !!
Line 125 $openId = $_SESSION['openId']; Line 126 echo "OpenId = ".$openId;
|