我的 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(); 才能拨打电话

关于javascript - XMLHttpRequest() 设置间隔,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27659974/

10-10 00:17
查看更多