0

我正在编写一个桌面小工具,它应该每 10 分钟左右刷新一次(这里是 10 秒)。我确定的是,每次执行 setTimeout 时,XML 都不会再次加载。

我不知道这是一个什么样的问题。我确保将对象设置为 null,但它们不会重新初始化,我只剩下一个空白 XML 对象。

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;
}
4

1 回答 1

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

于 2011-07-21T03:29:04.667 回答