1

Sometimes i face the following problem :

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

I get the following result!!

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

What's the reason to this problem and how to get the original arabic text ??

Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392
  • Take a look at "[The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)](http://www.joelonsoftware.com/articles/Unicode.html)". This is moste likely an inconsistent encoding/conversion issue. – Uwe Keim Jun 13 '12 at 11:29
  • 1
    When you add your parametres on your url, you must first make them UrlEncode() - do you ? – Aristos Jun 13 '12 at 11:39
  • @Aristos : Thanks but it's your javascript method just i add some parameters `jQuery.ajax({ url: "/LogAction.ashx?par_name=" + par_name + "&par_address=" + par_address,` – Anyname Donotcare Jun 13 '12 at 13:27
  • `http://stackoverflow.com/questions/10968725/how-to-log-the-link-click-which-make-form-submission` – Anyname Donotcare Jun 13 '12 at 13:29
  • 1
    @just_name ok then I give a solution here for that. – Aristos Jun 13 '12 at 13:32

1 Answers1

3

When you send string via url parametres, even via ajax and its utf-8 to avoid conflicts you must encode it with the javascript functions like the encodeURIComponent. Encode only the part of the value, not the parameters and the full url ! When then read the parameters on code behind they usually be UrlDecode by default, but if they not, do it manually.

For example the code from https://stackoverflow.com/a/10968848/159270 will be:

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();
    }
});

I did not include this encode on the previous answer because usually they are not send string as parameters, but variables, and because the answer was not focus on this detail.

You can also read : http://xkr.us/articles/javascript/encode-compare/

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • really thanks a lot , u are great. Could i ask two questions: – Anyname Donotcare Jun 13 '12 at 13:46
  • why type: "GET"? async: true, what does it means ? – Anyname Donotcare Jun 13 '12 at 13:47
  • 1
    @just_name You can try both true or false, and what is work better for your. The one is wait there until you have return for your request (the browser stop until the return) and the other is not stop there, and when you have the return from the request is running the function success. – Aristos Jun 13 '12 at 15:47
  • 1
    @just_name the get is mean that you send the parametres on the url, the post is post the parameters, and you place them on the param:, you get them from code behind using the response.form (try them both, if you send a lot of data the correct is to send them with POST) – Aristos Jun 13 '12 at 15:49