0

I use JQuery validation but somehow the Remote-validation can handle ØÆÅ-chars. It need to be charset= ISO-8859-1.

Can you see a way to handle this?

   jQuery.validator.addMethod("customerExist", function(value, element, param) {
    (...)
    var data = {};
    data["customer"] = value;
    $.ajax($.extend(true, {
        contentType: "application/json; charset=ISO-8859-1", 
        url: www+"validation.jsp",
        mode: "abort",
        dataType: "json",
        data:  data, //"{customer:'"+value+"'}",
        success: function(response) {
            alert("WORKS");
        }
    }, param));
    return "pending";
}, "");

Example of the validation method I have made. Where can the error be for this charset problem?

I have tried this solution with out luck.

ContentType contentType:

"application/x-www-form-urlencoded; charset=UTF-8", 

beforeSend

beforeSend: function(x){ x.overrideMimeType('application/json; charset=iso-8859-1'); },

The different pages: On HTML it is sat to:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 

JSP page(that are called)

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 

-

=== MY SOLUTION ===

Use decode in Javascript:

data["customer"] = encodeURIComponent(value);

And use URLDecoder.decode in JSP-page

<%@page pageEncoding="ISO-8859-1" contentType="text/html; charset=ISO-8859-1" %>
<%@ java.net.URLDecoder" %>
<% 
   String customer = URLDecoder.decode(request.getParameter("customer"), "UTF-8");
%>
boje
  • 869
  • 1
  • 16
  • 34
  • Check this: http://stackoverflow.com/questions/553463/jquery-ajax-character-encoding-problem – papaiatis Feb 13 '12 at 10:20
  • I have tried this solution with out luck. ContentType contentType: `"application/x-www-form-urlencoded; charset=UTF-8",` beforeSend `beforeSend: function(x){ x.overrideMimeType('application/json; charset=iso-8859-1'); },` **The different pages:** On HTML it is sat to: `` JSP page(that are called) `` – boje Feb 13 '12 at 11:30
  • Did you check what HTTP message actually goes out from the webpage? [Fiddler Web Debugger](http://fiddler2.com/fiddler2/) is a great tool for checking network traffic. – papaiatis Feb 13 '12 at 11:43
  • My solution was to `data["customer"] = encodeURIComponent(value);` and `String customer = URLDecoder.decode(request.getParameter("customer"), "UTF-8");` in JSP – boje Feb 13 '12 at 13:06

0 Answers0