Message from discussion
$.ajax() will null data property in config object results in missing Content-Length header in FF3
Received: by 10.151.142.16 with SMTP id u16mr795686ybn.20.1239890813335;
Thu, 16 Apr 2009 07:06:53 -0700 (PDT)
Return-Path: <jere...@gmail.com>
Received: from yw-out-1718.google.com (yw-out-1718.google.com [74.125.46.158])
by gmr-mx.google.com with ESMTP id 22si68483yxr.2.2009.04.16.07.06.52;
Thu, 16 Apr 2009 07:06:52 -0700 (PDT)
Received-SPF: pass (google.com: domain of jere...@gmail.com designates 74.125.46.158 as permitted sender) client-ip=74.125.46.158;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jere...@gmail.com designates 74.125.46.158 as permitted sender) smtp.mail=jere...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by yw-out-1718.google.com with SMTP id 5so277379ywm.22
for <jquery-dev@googlegroups.com>; Thu, 16 Apr 2009 07:06:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:mime-version:received:in-reply-to:references
:from:date:message-id:subject:to:content-type
:content-transfer-encoding;
bh=skMPXfitZS5gijHYjYda8PeA57KaoD+3WG+AAlYySmg=;
b=r0TDbjlucRvMRWELVy3+/VCLjOa9GKB7EDorweESZrhx7AqzEe50f7M+mJ7EnoHyAh
3N48rkiI+ObVqL7Bv8kWE1dNMTWCa95ZFsWrzNX2IHOpecOWYyksHOuO25NqHI/sdZBW
JrPV9bT7KTd+NavOwx6IbEqdGm4jzR9WxfObc=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=mime-version:in-reply-to:references:from:date:message-id:subject:to
:content-type:content-transfer-encoding;
b=Ts2/ehA2/LEJvJhaIdUXdgORdhARnPujHUbJ9yW6xca42+rbCU+BhSi7mGveLnC2TV
T/QXOlsYjWv9jKQUY/go2t3aBMqP7DOmDU9CcTF0s6+/e+RKx31gcWGlbYAC18Two6A+
ar/eSOWVadRBZImC62j2ACkAqXkXXzZmDnEoQ=
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Received: by 10.150.203.8 with SMTP id a8mr729514ybg.67.1239890812217; Thu, 16
Apr 2009 07:06:52 -0700 (PDT)
In-Reply-To: <0a37bb4c-b277-43e4-abb3-160f43f43054@p11g2000yqe.googlegroups.com>
References: <efe81923-3b4a-4b02-891b-e1be33f0c...@z19g2000yqe.googlegroups.com>
<7aca1ba7-658f-4552-8642-d3d0f19d7...@h28g2000yqd.googlegroups.com>
<0992779c-c6ab-4e40-bfbf-8841feb23...@u8g2000yqn.googlegroups.com>
<0a37bb4c-b277-43e4-abb3-160f43f43...@p11g2000yqe.googlegroups.com>
From: John Resig <jere...@gmail.com>
Date: Thu, 16 Apr 2009 10:06:37 -0400
Message-ID: <730bab940904160706v774342bekffdbed4ba22c4...@mail.gmail.com>
Subject: Re: [jquery-dev] Re: $.ajax() will null data property in config
object results in missing Content-Length header in FF3
To: jquery-dev@googlegroups.com
It seems like it'd be easy to special-case POST requests to make sure
that an empty string was sent. Could you file a bug on the issue?
Thanks!
--John
On Thu, Apr 16, 2009 at 9:38 AM, Rebecca Murphey <rmurp...@gmail.com> wrote=
:
>
> The issue didn't occur in IE; I haven't tested in C or S.
>
> As far as POSTing without data, I agree that this is illogical, but it
> was what the client (as in the person who pays me, not as in the
> browser) required to interface with their server-side code. I have
> tried repeatedly to get them to use GET where appropriate, to no
> avail.
>
> I made the change you suggested, setting the data to an empty string
> if it was null or undefined, and of course it worked fine.
>
> My more general question was, considering that different browsers
> handle the situation differently, is this something jQuery should
> resolve? Or is the onus on the developer to know that a data-less POST
> may cause issues for some users?
>
> On Apr 15, 10:28=A0am, DBJDBJ <dbj...@gmail.com> wrote:
>> for data sent jQ (-vsdoc.js version) says this :
>>
>> 5074# =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 // Set the correct header, if =
data is being sent
>> 5075# =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ( s.data )
>> 5076# =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 xhr.setRequest=
Header("Content-Type", s.contentType);
>>
>> before actually sending.
>> jQ does not set "Content-Length" specificaly. This is the job of
>> XmlHttpRequest.
>>
>> It is not clear from your message if you have tested this using IE or
>> C ?
>>
>> Although, in my book this is users/callers error: one should not
>> "POST" with no data, me thinks ;o)
>>
>> But if you think there is some logic in that you can simply do :
>>
>> $.ajax({
>> =A0 'url' : 'foo.php',
>> =A0 'data' : (! myData ? "" : myData) ,
>> =A0 'type' : 'POST',
>> =A0 'dataType' : 'json',
>> =A0 'success' : function(j) {
>> =A0 =A0 // whatever
>> =A0 }
>>
>> });
>>
>> Which might work since jQ does not check if user is sending empty
>> string as data.
>>
>> 4958# =A0 =A0 =A0 =A0 =A0 // convert data if not already a string
>> 4959# =A0 =A0 =A0 =A0 =A0 if ( s.data && s.processData && typeof s.data =
!=3D=3D "string" )
>> 4960# =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 s.data =3D jQuery.param(s.data=
);
>>
>> (same ...-vsdoc.js version )
>>
>> -- DBJ
>>
>> On Apr 14, 4:21=A0pm, Rebecca Murphey <rmurp...@gmail.com> wrote:
>>
>> > correction, the title of this should say
>>
>> > =A0 $.ajax() WITH null data property in config object results in missi=
ng
>> > Content-Length header in FF3
>>
>> > On Apr 14, 10:34=A0am, Rebecca <rmurp...@gmail.com> wrote:
>>
>> > > Just experienced this in Firefox 3, not sure whether it is desired
>> > > behavior, but discussed it with a fellow dev and we think it is not.
>>
>> > > I had an ajax request as follows:
>>
>> > > var myData =3D null;
>>
>> > > $.ajax({
>> > > =A0 'url' : 'foo.php',
>> > > =A0 'data' : myData,
>> > > =A0 'type' : 'POST',
>> > > =A0 'dataType' : 'json',
>> > > =A0 'success' : function(j) {
>> > > =A0 =A0 // whatever
>> > > =A0 }
>>
>> > > });
>>
>> > > Client was reporting a 411 HTTP response code on the request -- thei=
r
>> > > proxy was expecting a Content-Length header on the request, and wasn=
't
>> > > getting one. This also occurred if myData was undefined. It did *not=
*
>> > > occur when myData was {}.
>>
>> > > We hadn't detected this error internally because our requests weren'=
t
>> > > proxy'd. It seems Content-Length "should" always be there
>>
>> > >http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13
>>
>> > > and should be 0 if myData is null or undefined.
>>
>> > > I'm not sure whether this is just a Firefox issue, or something that
>> > > jQuery should address in the spirit of abstracting away browser
>> > > differences?
> >
>