views:

76

answers:

1

I am working on a Firefox extension, and in that extension I am trying to use AJAX to submit a form on a webpage. I am using:

var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
request.onload = loadHandler;
request.open("POST", url, true);
request.send(values);

to make the request, and it works ... mostly. The one problem is that the form has an authentication token on it, and I need to submit that token with my POST. I tried doing a GET separately to get this token, but by the time I made my second (POST) request my session had (evidently) changed, and the authenticity token was considered invalid.

Does anyone know of a way to use the XUL/Chrome Javscript to maintain a constant session across multiple requests (all "behind the scenes") for something this? I'm still a XUL n00b, so there may be a totally obvious alternative that I'm missing (eg. hidden IFRAME; I tried that briefly but couldn't get it to work).

A: 

I wound up going with a "hidden" IFRAME ... only I couldn't figure out how to hide it fully, so I just did:

<iframe flex="1" maxheight="1" maxwidth="1" showcaret="false"
        transparent="true" />

It created a small white box in the lower corner of the window, but it's hardly noticeable with the rest of the forms.

I then made "AJAX calls" through the IFRAME with:

iframe.contentDocument.getElementById("someInput").value = "Some value";
iframe.setAttribute('src', "https://yourServer.com/yourPseudoAjaxHandler");
machineghost