This is my ajax.php
I try to pass source1 to other php I got error when I use
$data = json_decode($_POST['source1']);
It says Undefined index
. What should I do?
<?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">
this is my ajax code
$('#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";
});
});
this is my sendinto.php
<?php
session_start();
$coba = $_SESSION['source1'];
echo $coba;
?>