0

I'm writing a desktop gadget which should refresh every 10 minutes or so (It's ten seconds here). What I've determined is that every time I execute the setTimeout, the XML doesn't load again.

I don't know what kind of problem this is. I made sure that the objects are set to null, but they don't re-initialize and I'm left with a blank XML object.

setTimeout("bg_load();getXML()",10000);

function getXML()
{                   
    stat = readSetting();
    url = "http://www.weather.gov/xml/current_obs/" + stat[0] + ".xml"

    rssObj = new XMLHttpRequest();
    rssObj.open("GET", url, false);
    rssObj.onreadystatechange = function() {
    if (rssObj.readyState === 4) {
        if (rssObj.status === 200) {    
            document.getElementById("gadgetContent").innerHTML = "";    
            rssXML = rssObj.responseXML;
        } else {
            var chkConn;
            document.getElementById("gadgetContent").innerHTML = "Unable to connect...";                
        }
    } else {
        document.getElementById("gadgetContent").innerHTML = "Connecting...";
        }
    }   
    rssObj.send(null);

getImage(rssXML);
getText(rssXML);

rssObj = null; rssXML = null;
}
Shad
  • 15,134
  • 2
  • 22
  • 34
Eric
  • 49
  • 4

1 Answers1

0

With SJAX (Synchronous Ajax), you shouldn't use 'onreadystatechange', and in the code, you pull the response text directly out of the XMLHttpRequest after sending.

Don't Use onreadystatechange: https://developer.mozilla.org/en/xmlhttprequest#onreadystatechange

Example of pulling the responseText out: http://www.hunlock.com/blogs/Snippets:_Synchronous_AJAX

Shad
  • 15,134
  • 2
  • 22
  • 34
  • And the problem with Synchronous calls is it can lock up the users browser if the server takes a long time to respond. Fun stuff! – epascarello Jul 21 '11 at 04:01
  • Thank you very much. I never would have figured this out on my own. – Eric Jul 21 '11 at 04:10