这是我的ajax.php
我尝试将 source1 传递给其他 php 使用时出现错误
$data = json_decode($_POST['source1']); 它说Undefined index。我该怎么办?
<?php
session_start();
$data = json_decode($_POST['source1']);
?>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<title></title>
</head>
<!-- <form action="sendinto.php" method="post"><center>
<button id="btnSelectedRows" type="button">test send</button>
</center>
</form> -->
<center>
<button id="btnSelectedRows" >test</button>
<!-- input type="submit" name="upload" value="Compare"> -->
</center>
<body>
</body>
</html>
<script type="text/javascript">
这是我的ajax代码
$('#btnSelectedRows').on('click', function() {
$.post({
type: "POST",
url: 'sendinto.php',
datatype : 'text',
data: {source1 : "heyo"} ,
// or GET
}).done(function(data) {
//Redirect to another page if you want...
window.location.href = "sendinto.php";
});
});
这是我的sendinto.php
<?php
session_start();
$coba = $_SESSION['source1'];
echo $coba;
?>
慕码人2483693
元芳怎么了