views:

114

answers:

1

I have a textarea, and am using $('#mytextarea').val(), and when i have text that is '£' i am getting the infamous black diamond with a question mark in it. �, When i package this up as a JSON packet it then gets sent to the server and it interprets it like this: "£" on the server side.

I am sending it to the server with this code:

jQuery.ajax({
        url: "aurl",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async : true,
        cache : false,
        type: "POST",
        processData : false,
        data: JSON.stringify(parameterMap)
});

I don't really understand why its just the £ symbol that is causing me issues, is it character encoding? is it server or client side?

Any ideas?

A: 

This looks like an encoding issue on server side. E.g. you could add a Filter before your servlet that has a doFilter like this one:

public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    if (request.getCharacterEncoding() == null)
        request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    chain.doFilter(request, response);
}

This will also set the correct encoding for the answers the servlet is sending.

Another hint you could check in your project: if you define some String constants in your code, check that the files are in the same encoding while editing and when the server delivers them.

Volker