AJAX gotcha

Fairlight fairlite at fairlite.com
Thu Mar 27 00:29:35 PDT 2008


This is the second time I've run into this.  It's annoying enough that I'll
put it out there to help anyone avoid debug hell.

Doing AJAX, specifically to fP here on this project, under Windows and IIS.

I had everything right except one thing.  Basically, Firefox claimed it was
sending my fields to fP (via a gateway), but the fields never showed up.  I
also saw a difference in -how- the data was submitted (thanks to
Firebug...don't leave 127.0.0.1 without it!).

Now...somewhere around 10 months ago, I ran into this problem once, and I
-thought- I had it fixed.  Well, I did at the time!  At the time, I found
that if you want to use POST rather than GET (advisable in many places),
there's a bit of oddness that goes on.  Namely, Apache will automatically
detect the POST and treat it properly, IIS will not do so all by itself.

With IIS, you -MUST- use the method:

     setRequestHeader('Content-Type','application/x-www-form-urlencoded')

If you don't, even if you send it via POST when preparing the object, it's
not actually sent correctly through IIS as a proper POST.  It's sent in a
half-baked state that isn't strictly conformant to GET or POST.  It took me
three systems and a separate debugging script to get the information that
let me find out that the perl CGI module has a failsafe for this half-arsed
scheme that was being triggered, but it wasn't compatible with what I do
elsewhere.

Now...almost a year ago, I figured out the need to set the type for IIS.
Today I'm pouring over "fresh" code based largely on the older code I
had written.  I compared the relevent sections regarding the fields and
the request object over 50 times.  FINALLY, when I was reading up on how
perl handles it and specifically when it does that, I said, "Hey, but I'm
already -doing- that!  WTF?!"  Then I looked at the code and found out
that I was working off of a second-to-last revision of the code, and I was
missing the "application/" part of the MIME type that I'd added as a bugfix
to the original once it was on the remote server--and hadn't updated this
file I was working on (I have like 20 backups of the live code, but it
wasn't updated in my HTML editor's development directory). *sigh*

Apparently it's easy to look at two lines of code 50 times and say, "I'm
requesting the type, it's right there!" and still miss the fact that the
requested types aren't identical (what the heck else was I gonna ask
for?!).  Go figure.  Forest for the trees, I guess.

But seriously, if you do AJAX and have to use POST under IIS, beware this
really annoying lack of functionality on their part.  One -must- work
around it.  Technically, it's documented in various places as a generic
methodology, but Apache has always done fine without an explicit request of
header change.  You know...a REAL web server actually handles this.  :)

Now fP is once again happily getting its data for yet another AJAX task
it's performing for us.  Thank goodness.

mark->
-- 
Fairlight->   ||| "You can go your own way / You can | Fairlight Consulting
  __/\__      ||| call it another lonely day..." --  |
 <__<>__>     ||| Fleetwood Mac                      | http://www.fairlite.com
    \/        |||                                    | info at fairlite.com


More information about the Filepro-list mailing list