4

I working on website with ISO-8859-1 charset. Request should be encoded partly by encodeURIComponent() , but this function encode with utf-8.

How can be request variables encoded by encodeURIComponent with ISO-8859-1 charset and not utf-8?(or other function that doing encoding with ISO-8859-1 or other way).

Update: maybe use escape() js function poper option in this case?

Thanks, Yosef

Ben
  • 25,389
  • 34
  • 109
  • 165
  • Where are you receiving the data? Any chance of converting the data on the server end? – Pekka Jan 09 '11 at 22:51
  • I receive data on client side, today I convert data in server side. I looking for solution with javascript(maybe lib- jquery or yui have good solution for that) – Ben Jan 09 '11 at 22:55
  • Javascript is traditionally very poor when it comes to character set conversion. What kind of a request are you encoding? Is maybe base64 an option? – Pekka Jan 10 '11 at 00:43

2 Answers2

0

I've made a script for escaping Windows-1250 characters. You can create a translation table by yourself or generate from Wikipedia with a translation table generation script I used. The script should work at least on IE 7, FF 3.6 and Opera 11 (haven't tested on other browsers).

Example code for jQuery:

var sBaseUrl = 'ajax.script.php';
var oData = {
    some_param : 'Zażółć gęślą jaźń',
    other_param : '1',
};

// build url
var url = localBuildURL(sBaseUrl, oData);

// get
$.ajax({
    url: url,
    dataType: 'text',   // JSON doesn't always parse...
    success: function(txt, status, xhr)
    {
        // do something with txt
        // or parse with: data = $.parseJSON(txt);
    }
});

Edit: Actually... No translation table is needed for ISO-8591-1. All characters in it are one byte only. The escape function should be sufficient.

Nux
  • 9,276
  • 5
  • 59
  • 72
-2

You should be fine. ISO-8859-1 I believe is completely encapsulated in UTF-8 with no issues.

Dave G
  • 9,639
  • 36
  • 41
  • 1
    Not true at all. All characters in ISO are indeed represented in UTF-8, but *only* the ASCII parts are byte identical between the two. All special characters have different mappings – Pekka Jan 09 '11 at 22:58
  • yes pekka right, example : 'isn't' => "'" special char encoded differently – Ben Jan 09 '11 at 23:10
  • Pekka is wrong. All characters in the set are one byte only and they are correctly converted with the `escape` function. – Nux Mar 25 '11 at 18:39