1

有时我会遇到以下问题:

string txt = con.Request.Params["Par_name"].ToString();//the original par value is arabic text

我得到以下结果!!

��� ������ ������� �����

这个问题的原因是什么以及如何获得原始阿拉伯文字?

4

1 回答 1

3

当您通过 url 参数发送字符串时,即使是通过 ajax 及其 utf-8 以避免冲突,您必须使用 .js 等 javascript 函数对其进行编码encodeURIComponent。只编码值的一部分,而不是参数和完整的 url !然后读取代码后面的参数时,默认情况下它们通常是 UrlDecode,但如果不是,请手动执行。

例如来自https://stackoverflow.com/a/10968848/159270的代码将是:

jQuery.ajax({
    url: "/LogAction.ashx?par_name=" + encodeURIComponent(par_name) + "&par_address=" + encodeURIComponent(par_address),
    type: "GET",
    timeout: 3000,
    async: true, // you can try and async:false - maybe is better for you
    data: action=4, // here you send the log informations
    cache: false,
    success: function(html) {
        jQuery("#FormID").submit();
    },
    error: function(responseText, textStatus, XMLHttpRequest) {                 
        jQuery("#FormID").submit();
    }
});

我没有在上一个答案中包含此编码,因为通常它们不是将字符串作为参数发送,而是变量,并且因为答案不关注这个细节。

您还可以阅读:http: //xkr.us/articles/javascript/encode-compare/

于 2012-06-13T13:35:18.337 回答