I am tying to use Post functions to send data from one php file to another, this is how my html code looks like (send.php):
<!DOCTYPE html>
<html>
<head></head>
<body>
<p>operator:<input type="text" , id="operator"></p>
<p>column:<input type="text" , id="columnName"></p>
<button id="Btn">Click</button>
<script src="js/jquery.min.js"></script>
<script src="js/actions.js"></script>
</body>
</html>
This is how my JavaScript looks like (actions.js):
$('#Btn').on('click', function () {
var array = {'operator': $('#operator'), 'columnName':
$('#columnName')};
$.ajax({
url: 'receive.php',
dataType: 'json',
type: 'post',
data: array,
success: function (data) {
if(data.success){
alert(data.operator);
} else {
alert("error");
}
}
});
});
And this is what my receive.php code looks like:
<?php
header('Content-type: text/javascript');
$json = array(
'operator' => "",
'columnName' => "",
);
if (isset($_POST['operator'],$_POST['columnName'])){
$operator = $_POST['operator'];
$columnName = $_POST['columnName'];
$json['operator'] = $operator;
$json['columnName'] = $columnName;
}
echo json_encode($json);
?>
When I fill both fields (column and operator) and I click on the button nothing happens! Any suggestions?