<?php
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
header('Content-type: application/json');
exit(json_encode(array('status' => TRUE, 'data' => nl2br(file_get_contents('msg.txt')))));
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="result"></div>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script type="text/javascript">
$(function(){
let message = function() {
$.get("", function(json) {
if (json.status) {
$("#result").html(json.data);
}
setTimeout(function(){
message();
}, 3000);
});
}
message();
});
</script>
</body>
</html>Test etmedim, basit bir örnek vermek istedim.