Tuesday, 15 May 2012

json - Spring MVC, response AJAX, russian symbols -


I am trying to use the controller to send a string like a reply to the Axax request. But unlike all the characters on the customer side '?' All the letters are from the Russian alphabet. I appreciate any help thank you! Here is the contoller code: @RequestMapping ("/ getfield") @ResponseBody public object getField (@RequestParam string field name) {// Return string characters full Russian alphabet return pagebuilder .getMultipleChoiceField (workspace Name); }

Ajax processing:

  $ ('# submit'). Click (function () {var drop = document.getElementById ('select_chzn'); Var spans = drop.getElementsByTagName ('span') [0]; var selected = spans.innerHTML; $ .post ('$ {pageContext. Request.contextPath} / getfield ', {' fieldName ': selected}, function (result) {var content = document.getElementById (' content '); warning (result); content creator html = content.innerHTML + result;} ); SetTimeout (function () {$ (". Chzn-select"). ();}, 50); event.preventDefault ();}); });    

OK, so it turns out that before I send all the symbols to the UTF8 code For the customer; So I have to code the string in UTF 8 and then send it to the client side; @RequestMapping ("/ getfield") @ResponseBody Public Object GetField (@RequestParam string fieldname) {byte [] field fieldActor = null; Try {fieldCharactersArray = pageBuilder.getMultipleChoiceField (fieldName) getBytes ("UTF8"); } Hold (exception e) {e.printStackTrace (); } Return field fielder; }

Cheers! Hope this will help anyone!

No comments:

Post a Comment