ajax 变量冲突,javascript

我将会话变量的值设置在一个文件中。 然后我以嵌套的方式使用了两个文件来执行任务。 然后内部文件将调用一个新文件,这是一个正常的php文件。 现在,在所有这三个文件(两个嵌套文件和一个新文件)中,Session变量均未显示正确的值。 我的意思是它的值没有设置。 我在每个文件的开头使用session_start()。 包括那些嵌套文件。 我是php的新手,我想知道它的问题是什么。

这些函数将调用ajax.php

function change_subcatagory()

{

var xhttp;

var val=document.getElementById('subcat').value;

if (val.length == 0) {

document.getElementById("txtHint").innerHTML = "";

return;

}

xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {

document.getElementById("question").innerHTML=this.responseText;

};

xhttp.open("GET", "ajax2.php?subcatagory="+val, true);

xhttp.send();

}

function change_catagory(){

var xhttp;

var val=document.getElementById('cat').value;

if (val.length == 0) {

document.getElementById("txtHint").innerHTML = "";

return;

}

xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {

document.getElementById("sub").innerHTML = this.responseText;

};

xhttp.open("GET", "ajax.php?catagory="+val, true);

xhttp.send();

}

function signout()

{

session_destroy();

?>

var mywindow = window.open("Login.php",'_self');

}

ajax.php

session_start();

$hostname="localhost";

$username="root";

$password="";

$databaseName="project";

$connect = mysqli_connect($hostname,$username,$password,$databaseName);

$catagory = $_GET["catagory"];

if($catagory!='catagory'){

$sql = "SELECT * FROM sub_catagory WHERE CID=$catagory";

$res = $connect->query($sql);

if($res){

echo '

style="top:10px; border-radius:16px; width:300px; height:30px">';

while($row = $res->fetch_assoc()){

echo ''; echo $row["sub_cname"];

echo '';

}

echo '


';

}

else

echo mysqli_error($connect);

}

?>

它将调用ajax2.php

session_start();

$hostname="localhost";

$username="root";

$password="";

$databaseName="project";

$connect = mysqli_connect($hostname,$username,$password,$databaseName);

$subcatagory = isset($_GET['subcatagory']) ? $_GET['subcatagory'] : '';

$_SESSION["subcatagory"]=$subcatagory;

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值