Its been asked a million different ways but this is specific to this code. This is not a duplicate post.
index.html
<html>
<head>
<script>
function ajax_post(){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = "process.php";
var fn = document.getElementById("s").value;
var vars = "s="+fn;
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(vars); // Actually execute the request
document.getElementById("status").innerHTML = "processing...";
}
</script>
</head>
<body>
<h2>Ajax Post to PHP and Get Return Data</h2>
Domain: <input id="s" name="s" type="text"> <br><br>
<input name="myBtn" type="submit" value="Submit Data" onclick="ajax_post();"> <br><br>
<div id="status"></div>
</body>
</html>
process.php
<?php
if($_GET["s"])
{
echo '<table>';
echo '<thead>';
echo '<tr>';
echo '<th width="200">CLASS</th>';
echo '<th width="150">HOST</th>';
echo '<th width="150">TYPE</th>';
echo '<th width="150">TTL</th>';
echo '<th width="150">TARGET</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
$result = dns_get_record($_GET['s'], DNS_ALL, $authns, $addtl);
foreach($result as $key=>$value){
echo '<tr>';
echo '<td>' . $value['class'] . '</td>';
echo '<td>' . $value['host'] . '</td>';
echo '<td>' . $value['type'] . '</td>';
echo '<td>' . $value['ttl'] . '</td>';
echo '<td>' . $value['target'] . $value['ip'] . '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
}
?>
The Problem
I can't get process.php to return the echo? If you access process.php?s=google.com DIRECTLY then it works fine and echo's the response without a hitch. Figures it probably something small but I can't figure it our can someone please point out my mistake please? Thanks!
DEMO
Form: http://main.xfiddle.com/14eb8a38/ajax/index.html
PROOF: http://main.xfiddle.com/14eb8a38/ajax/process.php?s=google.com