How do you submit an authenticated HTML form using XUL (Firefox extension) Javascript?

Posted by machineghost on Stack Overflow See other posts from Stack Overflow or by machineghost
Published on 2010-05-31T22:54:25Z Indexed on 2010/05/31 23:03 UTC
Read the original article Hit count: 205

Filed under:
|

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).

© Stack Overflow or respective owner

Related posts about xul

Related posts about nsixmlhttprequest