En basit şekilde kodlarım bunlar
index.php
<html>
<head>
<meta charset="UTF-8">
<script src="http://code.jquery.com/jquery-2.1.4.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var username= 'etkiliadam';
$(function(){
$.ajaxLoad = function(){
$.ajax({
type: "post",
url: "ajax.php",
data: {"username":username},
dataType: "json",
success: function(cevap){
if(cevap.hata){
$("#sonuc").html(cevap.hata);
}else{
$("#sonuc").html(cevap.veriler);
}
}
});
}
setInterval('$.ajaxLoad()',1000);
});
});
</script>
</head>
<body>
<div id="sonuc"></div>
</body>
</html>ajax.php
<?php
include "config.php";
if($_POST){
$username = $_POST['username'];
$query = mysql_query("SELECT * FROM islem where username='$username'");
$row = mysql_fetch_array($query);
$array['veriler'] = $row['kredi'];
echo json_encode($array);
}
?>Ajax.php de sorun manuel denedim çalışıyor. Tek sorun scriptte.
Bu kodu aynen aldım ve kopyaladım, çalışıyor herhangi bir sorun gözlemlemedim. Veritabanından ilgili kaydı güncellediğimde sayfa da yine güncelleniyor.
http://test.reddoc.net/ajax_example/