Hi,
I have kind of a weird problem and I can't figure what is wrong.
This is my Ajax php page :
<?php
// Configure connection settings
include('dbconnect.php');
include('functions.php');
// Fetch the data
$timestamp=$_GET['t'];
$dimanche='2013-03-03';
$samedi='2013-03-09';
$queryEvents=mysql_query("SELECT * FROM `events` WHERE `start_date`=`end_date` AND `start_date`>='$dimanche' AND `start_date`<='$samedi'");
while($resultEvents=mysql_fetch_array($queryEvents))
{
echo"<div id='drag-div-".$resultEvents['id']."' class='event-box' style='width:107px;height:".getCalHeight($resultEvents['start_heure'],$resultEvents['end_heure']);echo"px;top:".getCalStartTop($resultEvents['start_heure']);echo"px;left:".getCalWidth($resultEvents['start_date']);echo"px;'><p><b style='font-size:8px;'>".$resultEvents['start_heure'];echo" - ".$resultEvents['end_heure'];echo"</b><br />".$resultEvents['titre'];echo"<br />$timestamp</p><div id='event-resize-".$resultEvents['id']."' class='dragIcon' style='top:";echo getCalHeight($resultEvents['start_heure'],$resultEvents['end_heure'])-5;echo"px'></div></div>";
}
?>
Its a query from a database that will reload every 5 seconds to see if there is new entries. It works well. But if I add something below the while, the ajax request will load once, and then stop. It won't work anymore. Like this, doesnt work :
<?php
// Configure connection settings
include('dbconnect.php');
include('functions.php');
// Fetch the data
$timestamp=$_GET['t'];
$dimanche='2013-03-03';
$samedi='2013-03-09';
$queryEvents=mysql_query("SELECT * FROM `events` WHERE `start_date`=`end_date` AND `start_date`>='$dimanche' AND `start_date`<='$samedi'");
while($resultEvents=mysql_fetch_array($queryEvents))
{
echo"<div id='drag-div-".$resultEvents['id']."' class='event-box' style='width:107px;height:".getCalHeight($resultEvents['start_heure'],$resultEvents['end_heure']);echo"px;top:".getCalStartTop($resultEvents['start_heure']);echo"px;left:".getCalWidth($resultEvents['start_date']);echo"px;'><p><b style='font-size:8px;'>".$resultEvents['start_heure'];echo" - ".$resultEvents['end_heure'];echo"</b><br />".$resultEvents['titre'];echo"<br />$timestamp</p><div id='event-resize-".$resultEvents['id']."' class='dragIcon' style='top:";echo getCalHeight($resultEvents['start_heure'],$resultEvents['end_heure'])-5;echo"px'></div></div>";
}
echo"<div>test</div>";
?>
My ajax request file :
AjaxRefresh=true;
// Customise those settings
var seconds = 5;
var divid = "events-loop";
var url = "includes/ajax_events_loop.php";
////////////////////////////////
//
// Refreshing the DIV
//
////////////////////////////////
function refreshdiv(){
if(AjaxRefresh==true)
{
// The XMLHttpRequest object
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}
// Timestamp for preventing IE caching the GET request
fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}
var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;
// The code...
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp.responseText;
addResizeFunctionality();
setTimeout('refreshdiv()',seconds*1000);
}
}
xmlHttp.open("GET",nocacheurl,true);
xmlHttp.send(null);
}
else
{
setTimeout('refreshdiv()',seconds*1000);
}
}
// Start the refreshing process
var seconds;
window.onload = function startrefresh(){
setTimeout('refreshdiv()',seconds*1000);
}
What is wrong...?? Thanks...