Jump to content

Interval problem


robert_gsfame

Recommended Posts

this is what i did so far to refresh page using ajax periodically

 

function refreshflag()

{

var x=0;

if(x!=1)

{

  setInterval(checkit(),100);

}

}

 

function checkit()

{

var totalx=document.getElementById("totaluser").value;

var spx=totalx.split(";");

for(i=0;i<spx.length;i++)

{

  counter(spx);

}

}

 

 

function counter(x){

if (window.XMLHttpRequest)

  {

  xmlhttp=new XMLHttpRequest();

  }

else

  {

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

  }

var parameters="?em="+x;

xmlhttp.open("POST","refresh_flag.php",true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

xmlhttp.onreadystatechange=function()

  {

  if (xmlhttp.readyState==4 && xmlhttp.status==200)

    {

    document.getElementById(x).innerHTML=xmlhttp.responseText;

    }

  }

//xmlhttp.send(parameters)

alert(parameters);

}

 

and in refresh_flag.php

<?php echo rand(0,9);?>

 

 

the problem is that when i user alert i have the looping correctly but when i tried to get the responseText, i didn't get any result for each x. assuming that the

document.getElementById("totaluser").value="Ronan;Dean;Jay"

 

 

thanks for any helps

 

Link to comment
Share on other sites

Before that, your refreshflag() is messed up.

1. setInterval wants a function. That means you don't include the ()s.

2. You do not want it refreshing every 0.1 seconds. Trust me.

Separately,

- Don't include a ? in the POSTed values.

 

Do you have an HTML element with id="Ronan"? ="Dean"? ="Jay"?

Link to comment
Share on other sites

dont really get it..okay i have modified certain script

 

function refreshflag()

{

var x=0;

if(x!=1)

{

  setInterval(checkit(),1000);

}

}

 

function checkit()

{

var totalx=document.getElementById("totaluser").value;

var spx=totalx.split(";");

for(i=0;i<spx.length;i++)

{

  counter(spx);

}

}

 

 

function counter(x){

if (window.XMLHttpRequest)

  {

  xmlhttp=new XMLHttpRequest();

  }

else

  {

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

  }

var parameters="em="+x;

xmlhttp.open("POST","refresh_flag.php",true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

xmlhttp.onreadystatechange=function()

  {

  if (xmlhttp.readyState==4 && xmlhttp.status==200)

    {

    document.getElementById(x).innerHTML=xmlhttp.responseText;

    }

  }

//xmlhttp.send(parameters)

alert(parameters);

}

 

and in refresh_flag.php

<?php echo rand(0,9);?>

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.