Jump to content

ajax auto refresh only refresh the time stamp ?


jac.kock

Recommended Posts

hello all,

 

im a newbee with ajax and i have a simple function to refresh an information block on my site.

when the page loads it gets the string from de sql_db and displays it correctly, however when i wait to refresh i see that only the (debug) time stamp gets refreshed and the string stays the same even after 1 houre :(

 

the codes and places i submit hopely someone can get me on the right path to continu this project of mine :)

 

code voor de head section:

<?php
?>
<!-- before the </head> -->
<script type="text/javascript">
function loadXmlHttp(url, id) {
var f = this;
if (loadXmlHttp.xmlHttp){
 f.xmlHttp = loadXmlHttp.xmlHttp();
 f.el = document.getElementById(id);
 f.xmlHttp.open("GET", url, true);
 f.xmlHttp.onreadystatechange = function(){f.stateChanged();};
 f.xmlHttp.send(null);
}
else alert('Your browser does not support AJAX!'); // substitute your desired request object unsupported code here
}
loadXmlHttp.xmlHttp = null; loadXmlHttp.re = /^http/.test(window.location.href);
/*@cc_on @*/ // used here and below, limits try/catch to those IE browsers that both benefit from and support it
/*@if(@_jscript_version >= 5) // prevents errors in old browsers that barf on try/catch & problems in IE if Active X disabled
try {loadXmlHttp.ie = window.ActiveXObject}catch(e){};
@end @*/
if (window.XMLHttpRequest && (!loadXmlHttp.ie || loadXmlHttp.re))
loadXmlHttp.xmlHttp = function(){return new XMLHttpRequest();}; // Firefox, Opera 8.0+, Safari, others, IE 7+ when live - this is the standard method
else if (/(object)|(function)/.test(typeof createRequest))
loadXmlHttp.xmlHttp = createRequest; // ICEBrowser, perhaps others
else {
loadXmlHttp.xmlHttp = null;
// Internet Explorer 5 to 6, includes IE 7+ when local //
/*@if(@_jscript_version >= 5)
try{loadXmlHttp.xmlHttp = function(){return new ActiveXObject("Msxml2.XMLHTTP");};}
catch(e){try{loadXmlHttp.xmlHttp = function(){return new ActiveXObject("Microsoft.XMLHTTP");};}catch(e){}}
@end @*/
}
loadXmlHttp.prototype.stateChanged = function(){
if (this.xmlHttp.readyState == 4 && (this.xmlHttp.status == 200 || !loadXmlHttp.re)){
 this.el.innerHTML = this.xmlHttp.responseText;
 if(this.success){
  this.success();
 }
 }
}
</script>

 

the code in the page to call ajax to display and set auto refresh:

<style type="text/css">
.head-tr
{
border-color: #FF2A2A;
}
.head-td
{
border-width: 7px;
border-style: outset;
border-color: #FF2A2A;
}
</style>
<table width="100%">
 <tr>
   <td valign="top" align="top">
  <div id="headlights"></div>
  <script type="text/javascript">
  (function(){
  var statsrequest = new loadXmlHttp('modules/headlights/table.php?item=<? echo get_krant(); ?>&stamp=' + new Date().getTime(), 'headlights'), repeat = arguments.callee;
  statsrequest.success = function(){setTimeout(repeat, 10000);}; /* refresh after 30 sec. */
  })();
  </script>
</td>  
 </tr>
</table>

 

the code of the table.php file:

<table width="100%">
 <tr>
   <td class="head-td" height="150px" valign="top" align="top">
  <!-- start debug to see if we get something  THIS REFRESH WELL OTHER NOT  -->
  <i>[ <?=$_GET['stamp'];?> ]</i><br>
  <!-- end debug to see if we get something  -->
  <?=$_GET['item'];?>
</td>  
 </tr>
</table>

 

and finaly the code of the function get_krant()

<?php
function get_krant()
{
$res="";
$res1="";
$row="";
$item="";
$resl="";

$sql="Select * from headlights where delete_tab='0'";
$res1=mysql_query($sql);
$row=mysql_num_rows($res1);

$item=rand('1',$row);
$sql="Select * from headlights where krant_id='$item'";
$res=mysql_query($sql);

$resl=mysql_fetch_array($res);

return $resl["krant_item"];

}
?>

 

i hope that someone can tell me what im doing wrong :|

 

thnx all,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.