I have a very annoying problem With my Jquery based ajax live search. The search itself is working, but whenever my querystring contains 'ő' and 'ű' - only these two chars - , the value of the req.getParameter("sstring") is null! If the querystring does not have the mentioned chars, it returns the value successfully. I tried all possible encodings inluding UTF-8 but settled using 8859-2.
$.ajax({
type:"GET",
url: "/myApp/Protected/getStd",
contentType: "application/x-www-form-urlencoded; charset=iso-8859-2",
dataType:"application/x-www-form-urlencoded; charset=iso-8859-2",
data:"sstring="+escape(sstring)+"&options="+id+"&startrow="+startrow+"&valid="+Valid+"¬Valid="+notValid+"&searchForm=1",
async: true,
success: function(data){
$("#external").html(data);
}
})
I have to highlight that the pr开发者_如何转开发oblem only occures when the querystring is passed by Jquery. If I enter the QueryString to the browser manually the Servlet gets it properly. Any help is much appreciated.
As per the comments on the question:
INFO: sstring=min%u0151&options=1&startrow=0&valid=true¬Valid=true&searchForm=1
The sstring
parameter is not properly URL-encoded. You need encodeURIComponent()
instead of escape()
.
Make the method POST.
type:"POST",
You don't say method is GET and yet pass the data as part of the body of the request. A GET request works purely based on URLs.
If you want to use GET, do this:
$.ajax({
type:"GET",
url: "/myApp/Protected/getStd?sstring="+escape(sstring)+"&options="+id+"&startrow="+startrow+"&valid="+Valid+"¬Valid="+notValid+"&searchForm=1",
async: true,
success: function(data){
$("#external").html(data);
}
})
精彩评论