Ticket #4664 (closed bug: duplicate)
$.ajax() WITH null data property in config object results in missing Content-Length header in FF3
| Reported by: | rmurphey | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.4 |
| Component: | ajax | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
(See the full thread at http://groups.google.com/group/jquery-dev/browse_thread/thread/fe76bdc97c6f727b/c178b67e55b2d3d6?lnk=gst&q=length)
I had an ajax request as follows:
var myData = null;
$.ajax({
'url' : 'foo.php',
'data' : myData,
'type' : 'POST',
'dataType' : 'json',
'success' : function(j) {
// whatever
}
});
Client was reporting a 411 HTTP response code on the request -- their 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?
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Dup of #4044.