java - Ajax Call Trouble with Accents -
i have tried following line in ajax call suggested on internet:
contenttype: "application/json; charset=iso-8859-1"
but did not change anything. whenever make call ajax string parameter has accent example società , @ controller(i'm using java, spring framework), receive societÃ. have tried first utf-8 default (as far know) nothing. here full function:
function foo(customer, society) { $.ajax({ url: 'notmappedacostaffing.do', type: "get", contenttype: "application/json; charset=iso-8859-1", data: { customer: customer, society: society}, success: function(data) { $('#content').html(data); }, error: function(error) { alert("error" + error); } }); } and take values on backend
@requestmapping(method = requestmethod.get) public modelandview foocontroller(@requestparam("customer") final string customerparam, @requestparam(value="society",required=false) integer societyparam) {...} is there way resolve issue? in advance.
update: have still no idea why receive distorted parameter @ controller. when convert follows: how convert between iso-8859-1 , utf-8 in java? ,it comes out good. seeing works, tried again set utf-8 in ajax call no success... resolved issue not way. please share me if have better solution maybe on ajax call side. thanks
part of problem you're using http get, means data embedded in url itself, in query string ( http://example.org/?customer=foo&society=bar ). can lead problems when using special characters.
especially, contenttype property concerns body of request not have @ has little impact.
consider sending data http post (and remove custom contenttype) gives more power on encoding of data - sent in request body instead of url. might solve problem outright, or might need configure server use same encoding client - suggest utf-8 both parties.
Comments
Post a Comment