5 messages in com.googlegroups.google-desktop-developerXMLHttpRequest.send() eventually thro...
FromSent OnAttachments
then...@gmail.com18 Apr 2007 10:05 
then...@gmail.com30 Apr 2007 06:21 
fugged14 May 2007 10:22 
then...@gmail.com17 May 2007 07:38 
then...@gmail.com17 May 2007 12:16 
Subject:XMLHttpRequest.send() eventually throws error, can't send anymore until reload
From:then...@gmail.com (then@gmail.com)
Date:04/18/2007 10:05:08 AM
List:com.googlegroups.google-desktop-developer

I have created a gadget that pulls XML stats from a URL at 60 second intervals. I generally followed the format in the XMLHttpRequest sample code included in the SDK.

The gadget works perfectly, but after what seems like a consistent amount of time (I haven't timed it yet) it always starts to fail on the http.send(null) with the error "The system cannot locate the resource specified".

The URL is available - the error is not being caused because my script goes down. It seems that after a while the XMLHttpRequest object does not get created properly and fails on sending.

Is it possible there is a limit to how many times I can create a new XMLHttpRequest? I am properly setting http = null on any errors and setting http = null after my event fires on a 200 response.

I cannot seem to solve this or find any advice. Anybody run into this?

// Copyright (c) 2007 Bullet Games // All rights reserved

var STATS_URL = KEEPING_THIS_PRIVATE;

var http = null;

function onAddCustomMenuItems(menu) { menu.AddItem(ITEM_UPDATE, 0, updateStats); }

function onOpen() { pluginHelper.onAddCustomMenuItems = onAddCustomMenuItems; callUpdateStats(); }

function callUpdateStats() { updateStats(); view.setTimeout('callUpdateStats()', 60000); }

function updateStats() {

Stamp = new Date(); var Hours; var Mins; var Time; Hours = Stamp.getHours(); if (Hours >= 12) { Time = " P.M."; } else { Time = " A.M."; }

if (Hours > 12) { Hours -= 12; }

if (Hours == 0) { Hours = 12; }

Mins = Stamp.getMinutes();

if (Mins < 10) { Mins = "0" + Mins; }

// Set the labels clicksLabel.innerText = LOADING + Hours + ":" + Mins + Time; signupsLabel.innerText = ''; playersLabel.innerText = '';

// Cachebust so stats get updated var cachebuster = Math.round(999999*Math.random()); STATS_URL += "?cachebust=" + cachebuster.toString();

http = null; http = new XMLHttpRequest(); try { http.open("GET", STATS_URL, false); } catch (e) { // Catch invalid URLs http = null; clicksLabel.innerText = LOADING + " (GET ERROR)"; signupsLabel.innerText = e.message; return; }

// Set the callback for when the downloading is completed (or failed) http.onreadystatechange = onStatsData;

// Start the download try { http.send(null); } catch (e) { // Catch errors sending the request http = null; clicksLabel.innerText = LOADING + " (SEND ERROR)"; signupsLabel.innerText = e.message; return; } }

function onStatsData() { // Verify that the download completed if (http.readyState !== 4) return;

// Verify that the download was successful if (http.status !== 200) { http = null; clicksLabel.innerText = LOADING + " (" + http.status + ")"; return; }

try { var xmlobject = new DOMDocument(); xmlobject.loadXML(http.responseText); } catch (e) { // Catch errors reading DOM http = null; clicksLabel.innerText = LOADING + " (DOM ERROR)"; signupsLabel.innerText = e.message; return; }

var root = xmlobject.getElementsByTagName('rss')[0]; var signups = root.getElementsByTagName('signups')[0]; var signups_today = signups.getElementsByTagName('item')[0]; var today_date = signups_today.getElementsByTagName('date') [0].firstChild.nodeValue; var signups_today_amount = signups_today.getElementsByTagName('amount')[0].firstChild.nodeValue; var clicks = root.getElementsByTagName('clicks')[0]; var clicks_today = clicks.getElementsByTagName('item')[0]; var clicks_today_amount = clicks_today.getElementsByTagName('amount') [0].firstChild.nodeValue; var online = root.getElementsByTagName('online')[0]; var online_today = online.getElementsByTagName('item')[0]; var online_today_amount = online_today.getElementsByTagName('amount') [0].firstChild.nodeValue;

// Set the labels clicksLabel.innerText = HEADING_CLICKS + ' ' + clicks_today_amount; signupsLabel.innerText = HEADING_SIGNUPS + ' ' + signups_today_amount; playersLabel.innerText = HEADING_PLAYERS + ' ' + online_today_amount;

// Destroy the XMLHttpRequest object since it isn't being used anymore http = null; xmlobject = null; root = null; }