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
https://forums.phpfreaks.com/topic/220996-interval-problem/
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
https://forums.phpfreaks.com/topic/220996-interval-problem/#findComment-1144336
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
https://forums.phpfreaks.com/topic/220996-interval-problem/#findComment-1144338
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.