Jump to content

HELP: How to AUTO Refresh USing AjAX


eeuser

Recommended Posts

Hi,

 

I am really new at ajax myself but maybe I can help. I just got something similar going.

 

On mine, the script checks for a change in the db. When there is, it loads a different page. Is that what you had in mind? I'm assuming you are accessing your own db?

 

I used what I think is basic ajax off a website somewhere that check the page every  every ten seconds (see this line setInterval('sndReq()', 100000);)

 

Then, what I believe it does, is it goes to ajax.php which is just a regular php page that queries the db and if the db has changed then it will reload. That is done by "requiring" different pages depending on the db value

 

I posted above a problem I am having with it though. I experimented with iframes and if the displayed page has any animated fetures it causes the entire page to refresh

 

here is the code I use

 

<html>

<head>

<script type="text/javascript">

function createRequestObject() {

  var ro;

  var browser = navigator.appName;

  if(browser == 'Microsoft Internet Explorer') {

    ro = new ActiveXObject("Microsoft.XMLHTTP");

  } else {

    ro = new XMLHttpRequest();

  }

  return ro;

}

var http = createRequestObject();

 

function sndReq(action) {

  http.open('get', 'ajax.php');

 

  http.onreadystatechange = handleResponse;

  http.send(null);

}

 

function handleResponse() {

  if(http.readyState == 4) {

    var response = http.responseText;

   

document.getElementById('foo').innerHTML = response;

  }

}

setInterval('sndReq()', 100000);

</script>

<title>Internet Video Radio (INVIDRA)</title>

</head>

<body bgcolor="#FFFFF0">

<div id="foo">

retrieving data...';

 

</div>

</body>

</html>

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.