XMLHttpRequest () SetInterval

My setInterval fires but seems to XMLHttpRequest();

fail?

I get the first console.log()

, but not the second.

Any insight on this would be much appreciated.

Code below:

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);

      

+3


source to share


1 answer


You need to do jsonrequestIntervaled.send();

to make the call



+2


source







All Articles