<!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'];
?>