I am attempting to write an application that interacts with a library and gets values from it, and I can't seem to figure out how to get a php script to execute when a button is clicked.
Index.html
Chapter: <input type="text" name="chapter"><br>
Section: <input type="text" name="section"><br>
Problem: <input type="text" name="problem"><br>
<input type="button" class="button" name="insert" value="Get Input"
onClick="doStuff()"/>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
function doStuff()
{
var v1 = document.getElementById('chapter').value;
var v2 = document.getElementById('section').value;
var v3 = document.getElementById('problem').value;
$.ajax({
type: "POST",
url: "get-data.php",
data: {chapter:v1,section:v2,problem:v3},
success: function(data) {
alert(data);
}
});
}
</script>
get-data.php
<?php
function doit()
{
$chapter=$_GET['chapter'];
$section=$_GET['section'];
$problem=$_GET['problem'];
$command = "python proc.py init $chapter $section $problem";
$output = exec($command);
echo $output;
}
doit()
?>
the python script is confirmed to be working, and the php script is confirmed to be working when executed by using <form action="get-data.php">
but it always redirects to a simple page where the output is echo
to.