Reply to this topic  Start new topic
> My widget crashes randomly with XMLHttpRequests
tmar89
post Jun 3 2009, 01:44 PM
Post #1






Posts: 3
Joined: 14-April 09
Member No.: 64,825



My widget uses XMLHttpRequests and from time to time it will just crash in Windows, usually after being loaded for a few hours. There is no error in the debug log, but then again, the debug window crashes too so I can't see the last debug statements. I believe it has something to do with the XMLHttpRequest methods but for the life of me I can't figure it out. I tried all the status changes so it's not that. Seems like its the constant repeating of that requestStatus() function from the timer calling the processReqChange() ? Can someone just breeze through this to see what the problem could be?

Timer object from .kon file
CODE

<timer>
    <name>timer</name>
    <interval>1</interval>
    <ticking>true</ticking>
    <onTimerFired>
        requestStatus();
    </onTimerFired>
</timer>
            
<action trigger="onLoad">
<![CDATA[
    include( "main.js" );                
]]>
</action>


main.js
CODE

// Update the status of a site when logged in
function updateStatus() {        
    try {            
        // Do the update here
    } catch (err) {print(err);}        
}

// Process the XMLHttpRequest calls
function processReqChange() {    
    // When page returns, get the site status
    print("Ready State: " + req.readyState);
    if (req.readyState == 4) {                    
        print("Status Resp: " + req.status);
        if (req.status == 200) {    
            try {                
                // For this site, get the status and site id
                var site = req.responseXML.evaluate("nawiStatus/facid").item(0).firstChild.data;                    
                var siteStatus = req.responseXML.evaluate("nawiStatus/status").item(0).firstChild.data;
                if (site != null && siteStatus != null)
                    changeStatus(site, siteStatus);        
                //print(req.responseText);
                
                // Restart the timer object
                timer.ticking = true;
                timer.reset();
            } catch (err) {print(err);}
        }
    }
}

// Get the status for a site from NEESactivities
function requestStatus() {    
    // stop the timer so the process can complete
    timer.ticking = false;    
    // Get a site status            
    try {            
        if (req.readyState == 4 || firstLoad) {
            firstLoad = false;
            // Get next site index
            if (siteIndex < siteIDs.length-1)                            
                siteIndex++;    
            else
                siteIndex = 0;                
                            
            // Get the HTTP response
            req.open("GET","https://"+centralURL+"/activities/index.php?facid="+siteIDs[siteIndex]+"&eloc=getNawiStatus", true);
            req.send(null);                            
            print("https://"+centralURL+"/activities/index.php?facid="+siteIDs[siteIndex]+"&eloc=getNawiStatus");
        }
        else print("Still requesting data for " + siteNames[siteIndex]);            
    } catch (err) {print(err);}        
}    

// Change the status icon in the window
function changeStatus(id, status) {        
    if (status == "FLEX" || status == "NEES" || status == "SHARED" || status == "NON_NEES") {
        if (id == "226")
            UCLA.src = "Resources/"+status+".png";
        else if (id == "228")
            UCSB.src = "Resources/"+status+".png";
        else if (id == "280")
            UTexas.src = "Resources/"+status+".png";
        else if (id == "205")
            RPI.src = "Resources/"+status+".png";
        else if (id == "276")
            UCDavis.src = "Resources/"+status+".png";
        else if (id == "180")
            Cornell.src = "Resources/"+status+".png";
        else if (id == "191")
            Lehigh.src = "Resources/"+status+".png";
        else if (id == "275")
            Berkeley.src = "Resources/"+status+".png";
        else if (id == "278")
            Colorado.src = "Resources/"+status+".png";
        else if (id == "236")
            UIUC.src = "Resources/"+status+".png";
        else if (id == "244")
            UMN.src = "Resources/"+status+".png";
        else if (id == "274")
            Buffalo.src = "Resources/"+status+".png";
        else if (id == "277")
            UCSD.src = "Resources/"+status+".png";
        else if (id == "279")
            UNR.src = "Resources/"+status+".png";
        else if (id == "200")
            OrSt.src = "Resources/"+status+".png";    
        else print("Bad id, status: " + id + "," + status);
    }
}

// Pop up menu for each site
function openSite(siteID,x,y) {
    // open a particular site page
}

// Set specific statuses
function setStatusToNEES() {
    siteStatus = "NEES";
    changeStatus(selectedSite,siteStatus);
    updateStatus();
}
function setStatusToFLEX() {
    siteStatus = "FLEX";
    changeStatus(selectedSite,siteStatus);
    updateStatus();
}
function setStatusToSHARED() {
    siteStatus = "SHARED";
    changeStatus(selectedSite,siteStatus);
    updateStatus();
}
function setStatusToNONNEES() {
    siteStatus = "NON_NEES";
    changeStatus(selectedSite,siteStatus);
    updateStatus();
}

//---- END OF FUNCTIONS ----//

//---- VARIABLES ----//
var centralURL = "central.nees.org";
var selectedSite = 0;            // For the popup window update
var siteStatus = "FLEX";        // For the popup window update
var siteIndex = -1;                // For getting the site statuses
var siteIDs = [226,228,280,205,276,180,191,275,278,236,244,274,277,279,200];        // For getting site statuses and the popup update
var siteNames = ["UCLA","UCSB","UTexas","RPI","UCDavis","Cornell","Lehigh","Berkeley","Colorado","UIUC","Minnesota","Buffalo","UCSD","UNR","OSU"];    // For the popup window update
var req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;        
firstLoad = true;

// Initially request status of all sites
requestStatus();
NEESactivities.visible = "true";
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Fast Reply  Reply to this topic    Start new topic  
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members: