I have three functions: get_stat(sess) which takes an argument to send to a php script handlestat() which handles the response of the php script check_sms(sess_a) which should use setInterval to repeat itself - it relies on a variable disabled_stat to clear the timer
But it's not working, get_stat(sess) is not fired and it just stalls
var disabled_stat = false;
function get_stat(sess)
{
if(disabled_stat==false)
{
var url = "/sms_check_status.php?param=";
var title_f = document.getElementById('stat_title');
var stat_f = document.getElementById('stat_text');
title_f.innerHTML = ' ';
stat_f.innerHTML = ' ';
var myRandom=parseInt(Math.random()*99999999);
http.open("GET", url + escape(sess) + "&rand=" + myRandom, true);
http.onreadystatechange = handlestat;
http.send(null);
}
}
function handlestat()
{
var str_out = '';
var results = '';
if (http.readyState == 4)
{
results = http.responseText.split("~");
if(results[0]=='1')
{
document.getElementById('stat_title').innerHTML = results[1];
document.getElementById('stat_text').innerHTML = results[2];
if(results[3]=='1')
{
disabled_stat = true;
}
}
}
}
function check_sms(sess_a)
{
my_inteval = setInterval("get_stat(sess_a)", 1000);
if(disabled_stat==true)
{
clearInterval(my_inteval);
}
}
I have three functions: get_stat(sess) which takes an argument to send to a php script handlestat() which handles the response of the php script check_sms(sess_a) which should use setInterval to repeat itself - it relies on a variable disabled_stat to clear the timer
But it's not working, get_stat(sess) is not fired and it just stalls
var disabled_stat = false;
function get_stat(sess)
{
if(disabled_stat==false)
{
var url = "/sms_check_status.php?param=";
var title_f = document.getElementById('stat_title');
var stat_f = document.getElementById('stat_text');
title_f.innerHTML = ' ';
stat_f.innerHTML = ' ';
var myRandom=parseInt(Math.random()*99999999);
http.open("GET", url + escape(sess) + "&rand=" + myRandom, true);
http.onreadystatechange = handlestat;
http.send(null);
}
}
function handlestat()
{
var str_out = '';
var results = '';
if (http.readyState == 4)
{
results = http.responseText.split("~");
if(results[0]=='1')
{
document.getElementById('stat_title').innerHTML = results[1];
document.getElementById('stat_text').innerHTML = results[2];
if(results[3]=='1')
{
disabled_stat = true;
}
}
}
}
function check_sms(sess_a)
{
my_inteval = setInterval("get_stat(sess_a)", 1000);
if(disabled_stat==true)
{
clearInterval(my_inteval);
}
}
Share
Improve this question
edited May 20, 2011 at 17:48
Mike Samuel
121k30 gold badges227 silver badges254 bronze badges
asked May 20, 2011 at 17:42
Andy GeeAndy Gee
3,3522 gold badges33 silver badges48 bronze badges
1 Answer
Reset to default 9This line:
my_inteval = setInterval("get_stat(sess_a)", 1000);
won't work, because it's using a string expression, which'll end up evaluated in global scope where the variable sess_a
doesn't exist.
Instead, use:
my_inteval = setInterval(function() {
get_stat(sess_a);
}, 1000);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744780494a4593308.html
评论列表(0条)