0

I am submitting data with jquery ajax and receiving wrong characters on the server when using language other then English. For instance Russian or Georgian. What should I do to solve this problem and get correct unicode characters. I want to mention that form submitting works fine and I am receiving correct unicode chars but I need to use Ajax. below is the code.

$.ajax({
        url: url,
        data: {
            nameGeo: $('#sauceNameGeo').val(),
            nameEng: $('#sauceNameEng').val(),
            nameRus: $('#sauceNameRus').val(),
            descriptionGeo: $('#sauceDescGeo').val(),
            descriptionEng: $('#sauceDescEng').val(),
            descriptionRus: $('#sauceDescRus').val()
        }
    }).done(function(response) {
        $('#sauceNameGeo').val('');
        $('#sauceNameEng').val('');
        $('#sauceNameRus').val('');
        $('#sauceDescGeo').val('');
        $('#sauceDescEng').val('');
        $('#sauceDescRus').val('');
        $('.table-hotdog-sauces > tbody:last').append(response);
        alertify.success("Data has been saved");            
    });

Maybe I should use some Java APIs or something else on the front end. Any help would be appreciated.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
George
  • 255
  • 3
  • 18
  • 1
    make sure everything (pages, code, default charset for jvm) are utf-8 and life is beautiful. Otherwise, fall forever into an endless pit of character set whack a mole. – Taylor Nov 05 '13 at 16:52
  • The [docs](http://api.jquery.com/jQuery.ajax/) say that it's UTF-8 encoded by default. Based on Taylors comment I would trouble-shoot on the server side first. – Mike Edwards Nov 05 '13 at 16:52
  • why then form submit works fine if there is an issue with the server side? – George Nov 05 '13 at 16:59

1 Answers1

1

try this?
$.ajax({ type: "POST", url:url, data:JSON.stringify(data), contentType:"application/json; charset=utf-8"});

if you are using spring mvc server side:

@RequestMapping(value = "url", method = "POST", consumes = "application/json")

your method here(url is your actual url)

hope it helps

kyla
  • 396
  • 1
  • 8
  • do you have encoding setup in web.xml? if not check this post: http://stackoverflow.com/questions/5928046/spring-mvc-utf-8-encoding – kyla Nov 05 '13 at 17:08
  • no unfortunately it didn't help. This why I am receiving Georgian characters itself but not unicode characters and database saves them incorrectly. – George Nov 05 '13 at 18:09
  • did you set up jvm and db to use utf8? – kyla Nov 05 '13 at 19:09
  • no I added following Javascript method to my code found here: http://buildingonmud.blogspot.com/2009/06/convert-string-to-unicode-in-javascript.html modified it a little to get decimal instead of hex and it works fine now. Thanks a lot for helping. – George Nov 06 '13 at 04:09