topical media & game development

talk show tell print

professional-ajax-08-WeatherWidget-js-weatherwidget.js / js



  function AjaxWeatherWidget(oElement) {
      this.element = (oElement)?oElement:document.body;
      this.lastModified = null;
          
      this.getWeather();        
  }
  
  AjaxWeatherWidget.prototype.getWeather = function () {
          var oThis = this;
          
          var doTimeout = function () {
                  oThis.getWeather();
          };
          
          var oReq = zXmlHttp.createRequest();
      oReq.onreadystatechange = function () {
          if (oReq.readyState == 4) {
              if (oReq.status == 200) {
                                  var lastModified = oReq.getResponseHeader("Weather-Modified");
                                  
                                  if (lastModified != oThis.lastModified) {
                                          oThis.lastModified = lastModified;
                                          oThis.element.innerHTML = oReq.responseText;
                                  }
                          }
          }
      };
      
      oReq.open("GET", "weather.aspx", true);
      oReq.send(null);
      
      setTimeout(doTimeout,60000);
  };


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.