我的setInterval正在触发,但似乎XMLHttpRequest();不经历吗?
我得到第一个console.log(),但没有第二个.
任何对此的见解将不胜感激.
代码如下:
var countdown = 1000;
var region = "the_Pacific";
var jsonrequestInterval = function () {
console.log("The clock was updated");
var jsonrequestIntervaled = new XMLHttpRequest();
jsonrequestIntervaled.open("GET", 'myURL' + region, true);
jsonrequestIntervaled.onreadystatechange = function () {
if (jsonrequestIntervaled.readyState == 4) {
console.log("The request was made");
if (clock.getTime() >= jsonrequestIntervaled.responseText.match(/-?[1-9]\d+/g)) {
clock.setTime(jsonrequestIntervaled.responseText.match(/-?[1-9]\d+/g));
}
if (time > 300) {
countdown = 10000;
} else if (time < 60) {
countdown = 1000;
} else if (time < 300) {
countdown = 5000;
}
}
};
};
//problem not updating!!!!!!!!!!!!!!!!!!!!!
setInterval(jsonrequestInterval, countdown);
解决方法:
您需要执行jsonrequestIntervaled.send();才能进行通话