Client Login
Email:
Password:

Fun with Ajax and Firefox.

...and by "fun" I mean "WTF?!"

This code works just fine on Firefox 2.0.0.3 (on Windows XP):

var pReq = createRequest();
pReq.open( "GET", strURL, false );
pReq.onreadystatechange = updateChildControls;
pReq.send( null );

...updateChildControls() gets called just fine, and all is good.

Note, I deliberately called open() with the 3rd argument set to "false". It would take a while to explain, but this is actually creating the type of behavior in the UI that I'm hoping for, so this is intentionally a bit off from the norm (at least in most of my Ajax books).

However that same code does NOT run on Firefox 2.0.0.9 (on Windows XP), nor does it run on Firefox 2.0.0.6 on Ubuntu. No error messages on any of the machines. updateChildControls() simply never gets called!

I have to change it to this:

pReq.open( "GET", strURL, true );

...which I find rather annoying.

Can anyone tell me WHY?! If we're not supposed to flip that 3rd argument to "false", then shouldn't it throw an exception? Give me a message in the Error Console? Something?

Maybe this is just what happens when trying to write code the day after Thanksgiving. Can I blame a chemical in the turkey? :)

Interesting JavaScript quirk w/ stopPropagation()

I'm developing my app, using Firefox, and in one of the files, I have the following javascript:

el = document.getElementById( "frmProcess" ); addEvent( el, "submit", validate );

Simple enough, right? I have a form called "frmProcess", and when that form's "submit" event fires off, I want the function validate() to fire off as well.

That part works fine, and as you may have guessed, validate(), well, validates some data in the given form. If the validation fails, it calls this line of code:

evt.stopPropagation();

...which doesn't work. The "submit" event doesn't stop running. The form happily submits itself as if nothing went wrong. After somedebugging I found 2 things:

1. Changing the offending line of code from "evt.stopPropagation();" to "evt.preventDefault();" fixes the issue.

2. evt.stopPropagation() worked just fine on other events (blur, click, etc). But if I attach the "submit" event, it bombs.

Now the million dollar question is: WHY!?!?!

Firefox didn't report an error, and nothing else seemed to be causing an issue. So WHY in the name of all that's good does a "submit" event have to be handled differently than other events? Is this a bug in Firefox? Some valid DOM thing that I just can't find documentation for?

--n

 
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner