Keetah
Keetah

Reputation: 271

Encoding issue Java with XMLHttpRequest

I´m doing using XMLHttpRequest to do ajax call to my server. Suppose my call is:

http = new XMLHTTPRequest();
var url = "http://app:8080/search.action?value=ñ"
http.open("GET",url,true);
http.setRequestHeader("Content-type", "application/x-wwww-form-urlencoded;charset-UTF-8");
http.send(null);

In my action I receive in the parameter "value" a question symbol. I have properly configure tomcat with URIEncoding=UTF-8, also I have a Filter setting the CharacterEncoding to UTF-8 and in web.xml I set the page-encoding to UTF-8.

What I´m missing? why i´m receiving this characters wrong?.

EDIT: This is happening only in IE; in Safari or Firefox, I receive the ñ as expected. Any idea?

Upvotes: 1

Views: 293

Answers (1)

Giovanni
Giovanni

Reputation: 543

You need to encode the parameters in your request. Try this:

var url = "http://app:8080/search.action?value=" + encodeURI('ñ')

Upvotes: 1

Related Questions