I have a string that I'm trying to send over to my server code. I am getting a lot of these characters in the data - �
. Do I need to serialize the data or what? I'm using utf-8 encoding but that doesn't fix it. I think that something is happening to my data on the JQuery side. How do I fix this?
Here is what my JQ looks like.
var id = $('#id').val();
var dataString = 'id='+ id;
$.ajax({
type: "POST",
url: "http...",
data: dataString,
dataType: 'json',
success: function(data) {
...
Here is a sample string: `%ca 32d?
This string then becomes �32d?
with UTF-8 and Ê32d?
with iso-8859-1
EDIT:
I noticed that this encoding issue only happens when the string begins with %ca
. All oth开发者_运维问答ers seem to work as expected.
%xx in HTTP protocol is an encoded character, which the server will decode for you, even if you don't want to. You should either url encode your string before sending or replace every % with %25, which is the encoded equivalent of %. It's the same concept as with the \ characters. If you have \n in a string the engine will interpret it as a newline, even if n is part of a word for example.
Hope that helps.
精彩评论