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/