I've been working on a gadget that makes use of the XmlHttpRequest object to get data from a web application. Currently, I'm having a problem in that the web app requires the user to log in by first requesting an auth token, then sending the user to a webpage (with that token as a parameter), and then once the user has logged in, requesting the users sessionId. I have the first part working, I can get an auth token just fine and then I try to load up the login page in a flyout (using the iframe trick), but I keep getting navigation cancelled. Also, as soon as my gadget opens the flyout, it seems to reset itself. I traced the behaviour to the fact that onreadystatecomplete was being called again (I only do my initialization code when readyState == "complete").
Has anyone else encountered this behaviour I'm wondering if I'm doing something wrong, or if I will should just code around (by writing a state variable into the gadget settings object) or something along those lines.
Heh, sorry if that was incomprehensible, it's late and i've been trying to figure this out for a while!
Has anyone else encountered this behaviour I'm wondering if I'm doing something wrong, or if I will should just code around (by writing a state variable into the gadget settings object) or something along those lines.
Heh, sorry if that was incomprehensible, it's late and i've been trying to figure this out for a while!

Gadget resets?
nzmike
I think I figured out what was causing the problem with the gadget reseting itself.
In my main gadget.htm form, I was using <a href="#"> </a> for interation. This was causing the gadget to 'reset' everytime you clicked on one.
Thanks for the help though!
Kishorepbp
Gadget resets itself... What is it doing
onreadystatecomplete... I've never seen it fire twice, could be related to the site. I'd just code around it in the way you mention.
VenkatRaghavan
If I set an arbitary url instead of using loginURL -- it works fine, but trying to use loginURL results in navigation cancelled. I added some debug output and it seems to be coming back to my reset problem! (and the onreadystatechanged event being fired multiple times). I used DebugView and here is the trace of my gadget.
Just for completeness here is my document.onreadystatechange function
document.onreadystatechange = function() { //try and get the debugWindow debug("Enter document.onreadystatechange"); if (document.readyState == "complete") { debug(" document completed, current state='" + System.Gadget.Settings.read("GadgetState") + "'"); switch(System.Gadget.Settings.read("GadgetState")) { case "initial": //... break; case "wait_login": //... break; case "loggedin": //... break; case "working": //... break; case undefined: case "": default: System.Gadget.Settings.write("GadgetState", "initial"); document.onreadystatechange(); return; break; }; //check the session sessionID = System.Gadget.Settings.read("sessionID"); debug(" tried to get sessionID: " + sessionID); if (sessionID == undefined | sessionID == "") { //... } else { //... } } debug("Exit document.onreadystatechange") }Ted.
From past experience, you'll need to write the IFrame HTML to the Flyout body, not use a static IFrame and change it's URL.
ie
System.Gadget.Flyout.document.body.innerHTML="<IFRAME id='loginWindow' src='" + loginURL + "' ...>"
oris
I get the Navigation cancelled for any site I try to navigate too (ie: www.live.com). I'm wondering if it is not the method I'm using to set the url in the iframe
function doFlyout() { debug("Enter doFlyout"); System.Gadget.Settings.write("GadgetState", "wait_login"); loginURL = "http://www.live.com"; System.Gadget.Flyout.file = "login.htm"; System.Gadget.Flyout.show = true; debug(" Displayed flyout"); document.getElementById('logintext').innerHTTP = TEXT_WAIT_LOGIN; document.getElementById('working').style.visibility = "hidden"; document.getElementById('donelogin').style.visibility = "visible"; debug("Exit doFlyout"); } System.Gadget.Flyout.onshow = function() { debug("Enter Flyout.onshow"); var doc = System.Gadget.Flyout.document; doc.getElementById("loginWindow").src = loginURL; debug("Exit Flyout.onshow"); }And on the note of the gadget resetting itself. It is very strange, it seems to flash as if it is redrawing itself but then it called onreadystatecomplete again (Actually it calls it twice, but only once with the readyState == "completed". The only thing I could think of is that it is being called when my xmlhttprequest gets a response back (but the handler for the xmlhttprequest.onreadystatecomplete does get called as it is supposed to, so perhaps that is not the problem).