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.

3
  • 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. Commented Nov 5, 2013 at 16:52
  • The docs say that it's UTF-8 encoded by default. Based on Taylors comment I would trouble-shoot on the server side first. Commented Nov 5, 2013 at 16:52
  • why then form submit works fine if there is an issue with the server side? Commented Nov 5, 2013 at 16:59

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

do you have encoding setup in web.xml? if not check this post: stackoverflow.com/questions/5928046/spring-mvc-utf-8-encoding
no unfortunately it didn't help. This why I am receiving Georgian characters itself but not unicode characters and database saves them incorrectly.
did you set up jvm and db to use utf8?
no I added following Javascript method to my code found here: buildingonmud.blogspot.com/2009/06/… modified it a little to get decimal instead of hex and it works fine now. Thanks a lot for helping.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.