2014-12-26 59 views
3

我的setInterval正在觸發,但似乎XMLHttpRequest();沒有經過?XMLHttpRequest()SetInterval

我得到第一個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); 

回答

2

你需要做jsonrequestIntervaled.send();撥打電話

+0

它總是逃脫我最簡單的事情。 :P 非常感謝! – LSD