Hi,
I have to post forms in iso-8859-1 encoding so I tried using the following ajax option :
- contentType:"application/x-www-form-urlencoded;charset=iso-8859-1"
A problem appeared when I had to serialize forms that contained accents or '+', because
serialize uses
encodeURIComponent which always encode in UTF-8.
I had to implement the following
serializeLatin to overcome the problem :
- // Kind of encodeURIComponent for ISO-8859
- function escapeComponent(str) {
- return escape(str).replace(/\+/g, '%2B');
- }
-
- // Kind of $.param for ISO-8859
- $.paramLatin = function( a ) {
- var s = [];
- $.each( a, function( i, kv ) {
- s[ s.length ] = escapeComponent(kv.name) +"="+ escapeComponent(kv.value);
- });
- return s.join("&").replace(/%20/g, '+');
- };
-
- // Kind of $.fn.serialize for ISO-8859
- $.fn.serializeLatin = function() {
- return $.paramLatin( this.serializeArray() );
- };
As some web apps still use latin encoding, I suggest to provide serialize options that manage encoding.