Hoi,
Hoe kan ik een pagina die info toont uit een database (mysql) verversen met data zonder dat de pagina een refresh krijgt?
Dus zodra er een verandering is met data; dat dit gelijk getoond wordt.
2.470 views
- Ariën - op 21/07/2016 15:28:37
Het enige wat AJAX doet is de data a-synchroon ophalen. De gegevens uit de database ophalen moet je zelf fabriceren met PHP en MySQL. Dus maak die stap maar eens eerst.
<script language="JavaScript">
var pages = new Array(
'/screen/klasse.php?klasse=ZAT1'
,'/screen/klasse.php?klasse=ZAT2'
,'/screen/klasse.php?klasse=ZON'
,'/screen/nieuws1.php'
,'/screen/klasse.php?klasse=A'
,'/screen/klasse.php?klasse=B'
,'/screen/klasse.php?klasse=C'
,'/screen/klasse.php?klasse=D1'
,'/screen/klasse.php?klasse=D2'
,'/screen/pin1.php'
,'/screen/klasse.php?klasse=E1'
,'/screen/klasse.php?klasse=E2'
,'/screen/klasse.php?klasse=F1'
,'/screen/klasse.php?klasse=F2'
,'/screen/klasse.php?klasse=MP'
,'/screen/klasse.php?klasse=M'
,'/screen/klok.php'
,'/screen/buien.php'
);
var pagesstand = new Array(
'/stand/tussen.php'
,'/stand/stand.php'
,'/screen/klasse.php?klasse=A'
,'/screen/stand.php?teamID=9'
,'/screen/klasse.php?klasse=B'
,'/screen/stand.php?teamID=14'
,'/screen/klasse.php?klasse=ZAT1'
,'/screen/klasse.php?klasse=ZAT2'
);
var i=0;
var time=10000; // this is set in milliseconds
var countDownInterval=12;
var d = new Date();
var m = d.getMinutes();
var h = d.getHours();
if ( m < 10)
var m = m + 10
var time = (" " + h + m+" ")
//alert (time)
// below should be 1430 1830 when comp starts
if ( time >= 1430 && time <= 1830 )
{
var pages=pagesstand;
}
function pageChange() {
document.getElementById("frame").src=pages[i];
if(i==pages.length) {
i=0;
window.location.reload()
}
i++;
}
onload=pageChange;
var countDownTime=countDownInterval+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=countDownInterval;
clearTimeout(counter)
//window.location.reload()
pageChange();
countDownTime++;
countDown();
return
}
if (document.all) //if IE 4+
document.all.countDownText.innerText = countDownTime+" ";
else if (document.getElementById) //else if NS6+
document.getElementById("countDownText").innerHTML=countDownTime+" "
else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
//document.c_reload.document.c_reload2.document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
//document.c_reload.document.c_reload2.document.close()
}
counter=setTimeout("countDown()", 1000);
}
function startit(){
if (document.all||document.getElementById) //CHANGE TEXT BELOW TO YOUR OWN
document.write('<div class="countpos"><b id="countDownText">'+countDownTime+' </b></div>')
countDown();
}
if (document.all||document.getElementById)
startit();
else
window.onload=startit;
</script>
<div id="container">
<iframe id="frame" src="" bgcolor=red width=100% height=1024 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" allowTransparency="true">
<?php
include_once('news.php');
?>
</iframe>
</div>
<?php
include('footer.html');
?>
Patrick G op 22/07/2016 12:11:27Dus wat ik eigenlijk wil een standaard pagina die alleen de data refreshed.
loadData();
function loadData() {
$.ajax({
url: "script.php",
cache: false,
success: function(html){
$(".result").empty().html(html);
setTimeout(function () {
loadData();
}, 30000); // 30 sec.
},
error:function (xhr, ajaxOptions, thrownError){
$(".result").empty().html('Er is een fout opgetreden:'+ xhr.status + ' '+ thrownError);
}
});
}
setTimeout(function() { $("#div1").slideUp( "slow").fadeIn(1000).delay(1000).load("/screen/klasse.php?klasse=E1"); }, 0000);
setTimeout(function() { $("#div1").slideUp( "slow").fadeIn(1000).delay(1000).load("/screen/klasse.php?klasse=D1"); }, 12000);