新手求教ajax设置session的问题

oSuperkinG oSuperkinG 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是js代码:
            function searchbutton(){
var str = document.getElementById("textarea").value;
if(str != null){
alert(str);
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
window.location.href = "function/search.php";
}
}
xmlhttp.open("get","function/search.php?text="+str,true);
xmlhttp.send();
}
}


这是处理请求的页面:
<?php
session_start();
$_SESSION['searchtext'] = $_GET["text"];
echo "欢迎来到搜索界面!";
echo "您搜索的内容为:".$_SESSION["searchtext"];
?>


为何跳转到search.php页面后,session还是空?if(xmlhttp.readyState == 4 && xmlhttp.status == 200)这句话不是说响应已经就绪才会跳转吗?请前辈告诉我我那里理解错了?
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
oSuperkinG
Ajax 52,778 成员 25,334 内容