爱玺玺

爱玺玺的生活日记本。wx:lb87626

ajax保存session,关于Ajax提交后session里面为空的问题

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<script type="text/javascript" src="js/jquery.min.js"></script>

</head>

<body>

<input type="button" value="点击" onclick="test()" />

</body>

</html>

<script type="text/javascript">

function test(){

$.ajax({

xhrFields: {

withCredentials: true

},

url:"sess.php",

dataType:"json",

xhrFields: {

withCredentials: true

},

data:{phone: 123456},

type:"get",

success:function(data){

                alert(data);

},

error:function(data){

console.error(data);

}

}); 

}

</script>



sess.php


<?php 

session_start();

$_GET['phone'];

$_SESSION['phone']=$_GET['phone'];

echo $_SESSION['phone'];

 ?>


发表评论:

Powered By Z-BlogPHP 1.4 Deeplue Build 150101

Copyright Your WebSite.Some Rights Reserved.

蜀ICP备11021721号-5