Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XMLHttpRequest on close of dialog never finishes

14 views
Skip to first unread message

Jake

unread,
Nov 2, 2006, 8:54:42 PM11/2/06
to
I am writing a firefox extension. I have a dialog window that accepts
user input. I use the onDialogAccept handler to execute an
XMLHttpRequest to post the data to my server. The problem is that the
callback from the XMLHttpRequest is never called. It seems that once
the dialog disappears, the XMLHttpRequest object that I created becomes
invalid. Is there any way to keep it from getting invalidated?

Here are some code snippets

In XUL file:

<dialog id="MyDialog"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
buttons="accept, cancel" orient="vertical" ondialogaccept="SendInfo()"
title="Dialog">
<script type="application/x-javascript"
src="chrome://myapp/content/script.js" />

In script.js:

var globalHttpRequest;

function SendInfo(url) {
globalHttpRequest = new XMLHttpRequest();
globalHttpRequest.onreadystatechange = function(aEvt) {
if (globalHttpRequest.readyState == 4) {
if(globalHttpRequest.status == 200) Error_Log("Loaded");
else Error_Log("Error loading page");
}
};
globalHttpRequest.open("GET", url, true); //true means async
globalHttpRequest.send(null);

}

What happens is that I get a javascript error that globalHttpRequest is
not defined on the line where I compare it to 4.

Eric H. Jung

unread,
Nov 2, 2006, 9:19:32 PM11/2/06
to dev-ext...@lists.mozilla.org
Send the request synchronously instead of asynchronously.
Change:

globalHttpRequest.open("GET", url, true); //true means async
to:
globalHttpRequest.open("GET", url, false); //false means sync

In XUL file:

In script.js:

var globalHttpRequest;

}

_______________________________________________
dev-extensions mailing list
dev-ext...@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-extensions

Jake

unread,
Nov 2, 2006, 9:30:23 PM11/2/06
to
Nope, that doesnt work. It's also not a great idea because the server
side processing could take a long time, and the dialog will be stuck
until it completes.

There are other global variables that are also being unset when the
dialog closes. Anyone know why?

Cheba

unread,
Nov 3, 2006, 2:54:29 AM11/3/06
to
You can try to perform request in context of other window (say FF
browser window which opened your dialog). Or you can return false in
your accept event handler and close window from code when request is
finished.

Nickolay Ponomarev

unread,
Nov 3, 2006, 3:01:16 AM11/3/06
to Jake, dev-ext...@lists.mozilla.org
The variables declared in a <script> are tied to the window. If you
want to do processing independent of any windows, do it in an xpcom
component.

0 new messages