Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5022 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

[PATCH] Ajax.Request should specify UTF-8 encoding in headers

Reported by: james@jberry.us Assigned to: sam@conio.net
Priority: high Milestone:
Component: Prototype Version:
Severity: normal Keywords: ajax request encoding headers
Cc:

Description

Since JavaScript encodes URIs as utf8, the Content-Type header set by prototype should set the charset parameter:

      contentType:  'application/x-www-form-urlencoded',

should be:

      contentType: 'application/x-www-form-urlencoded; charset=UTF-8',

In the absense of this, certain server-side agents (such as java servlets) get very confused about what they are seeing.

Attachments

serialize-encoding.diff (1.2 kB) - added by mislav on 10/08/06 13:24:55.
allows to hook into Form.encodingMethod
ajax-encoding.diff (3.5 kB) - added by mislav on 10/08/06 13:28:45.
Polishing ajax.js, added 'encoding' option

Change History

10/08/06 13:24:55 changed by mislav

  • attachment serialize-encoding.diff added.

allows to hook into Form.encodingMethod

10/08/06 13:28:45 changed by mislav

  • attachment ajax-encoding.diff added.

Polishing ajax.js, added 'encoding' option

10/08/06 13:42:02 changed by mislav

  • keywords set to ajax request encoding headers.
  • priority changed from normal to high.
  • summary changed from Prototype Ajax.Request should default set default utf-8 charset in Content-Type header. to [PATCH] Ajax.Request should specify UTF-8 encoding in headers.

First of all, see #3879 that now points here. Also, read about encoding functions in JavaScript (Prototype uses encodeURIComponent).

I've added 2 patches. Serialize-encoding is about making Form.serialize use Form.encodingMethod function, which by default is a reference to encodeURIComponent. If someone wants to change this, he can set encodingMethod to something else (like escape).

Ajax-encoding is what James suggests in this ticket. It adds 'encoding' option to Ajax (among method, parameters...). The patch also polishes ajax.js a bit, but doesn't really change any other features.

10/08/06 17:59:27 changed by david

  • owner changed from sam to sam@conio.net.

10/09/06 10:01:33 changed by mislav

This ticket (the second patch, actually) is now superseded by #6366.

11/19/06 12:33:28 changed by mislav

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [5448]. There is now an encoding option for Ajax.Request that defaults to "UTF-8".