I have adjusted my code slightly to call the file a file from Ajax however it does not show it in real time, it just prints it out once the script is complete. I am sure this is an Ajax thing, maybe some one could help?
index.php
<html>
<head>
<link rel="stylesheet" href="css/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script src="scripts/jquery-ui.min.js"></script>
<script src="scripts/jquery-ui.js"></script>
<script language="javascript">
function clearform() {
document.getElementById("json").value="";
}
</script>
<script>
$(function() {
$( "#tabs" ).tabs();
});
$.ajax({
url: "ant.php",
type: 'GET',
dataType: 'html',
success: function(data){
$("#ant").html(data);
}
});
</script>
<title>Add Manual Event Data</title>
<?php
if (empty($_POST["comment"])) {
$comment = "";
}
else {
$cleaned = test_input($_POST["comment"]);
$comment = ($_POST["comment"]);
}
function test_input($data) {
$data = trim($data);
$data = addslashes($data);
return $data;
}
?>
</head>
<body>
<div id="tabs" class="body-check">
<ul>
<li><a href="#tabs-1">Event By String</a></li>
<li><a href="#tabs-2">Add Event Form</a></li>
</ul>
<div id="tabs-1">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<center><h1>Add Event Data:</h1></center>
<p>
<textarea id="json" name="comment"><?php echo $comment;?></textarea>
</p>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if (isset($cleaned)){
echo '<div id="ant"></div>';
}
?>
</div>
<div id="tabs-2">
<h1>Hello!</h2>
</div>
</div>
</body>
</html>
ant.php
<?php
$json_arg = escapeshellarg($cleaned);
$proc = popen("sudo /var/www/html/scripts/set_vars.sh $json_arg 2>&1", 'r');
echo '<pre>';
while (!feof($proc)){
echo fread($proc, 256);
@flush();
@ob_flush();
echo "<script>window.scrollTo(0,99999);</script>";
usleep(200);
}
pclose($proc);
echo '</pre></div>';
echo '<script>';
echo 'window.scrollTo(0,99999);';
echo 'setTimeout( function ( ) { alert( "Event Added!" ); }, 2000 );';
echo 'clearform();';
echo '</script>';
?>
I am assuming that it's because AJAX waits for the script to complete before showing it. I also know that I haven't completed the function yet as I still need to 'POST' a variable, but 1 thing at a time.
Thank you