is it possible to add an php code directly to the Ajax Query instead of extern url?
My Ajax:
<div id="show"></div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
setInterval(function () {
$('#show').load('data.php')
}, 3000);
});
</script>
i dont want use the extern file data.php
, can i add an php code directly?
Like this one:
<?php
include('includes/config.php');
if ($connection->connect_error) {
die("Connection error: " . $connection->connect_error);
}
$result = $connection->query("SELECT input_address FROM payments");
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo $row['input_address'] . '<br>';
}
} else {
echo "Wait..";
}
?>
Example:
$('#show').load(' <?php myphpcode?> ')
The question is a bit baffling, the purpose of AJAX is to allow for the browsers (front-end), which run JavaScript, to communicate with servers (back-end) that may be using other technologies. The servers may be running any variety of environments, among them, PHP.
If you want to keep a single language between front and back end, take a look at node.js.