如何通过带有ISO-8859-1字符集而不是utf-8的encodeURIComponent编码请求变量? [英] How can be request variables encoded by encodeURIComponent with ISO-8859-1 charset and not utf-8?
问题描述
我在网站上使用ISO-8859-1 charset。
请求应部分由encodeURIComponent()编码,但此函数使用utf-8编码。
I working on website with ISO-8859-1 charset. Request should be encoded partly by encodeURIComponent() , but this function encode with utf-8.
如何使用ISO-8859对encodeURIComponent编码的请求变量进行编码-1 charset而不是utf-8?(或用ISO-8859-1或其他方式进行编码的其他功能)。
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).
更新:
也许可以使用在这种情况下escape()js函数poper选项?
Update: maybe use escape() js function poper option in this case?
谢谢,
Yosef
Thanks, Yosef
推荐答案
我是制作了一个用于转义Windows-1250 字符的脚本。您可以自己创建翻译表,也可以使用我使用的翻译表生成脚本从Wikipedia生成翻译表。该脚本至少应该在IE 7,FF 3.6和Opera 11上运行(尚未在其他浏览器上测试过)。
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).
jQuery的示例代码:
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);
}
});
编辑:实际上...... ISO不需要转换表8591-1。其中的所有字符仅为一个字节。 转义
功能应该足够了。
Actually... No translation table is needed for ISO-8591-1. All characters in it are one byte only. The escape
function should be sufficient.
这篇关于如何通过带有ISO-8859-1字符集而不是utf-8的encodeURIComponent编码请求变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!