0

I'm sending a string using jQuery AJAX POST and JSON:

$.ajax({
    type: "POST",
    dataType: "JSON",
    url: "someUrl.asp?param1=someParam1",
    contentType: "charset=utf-8",
    data: JSON.stringify({
        some_code: $( "#some_code" ).length > 0 ? $("#some_code").val() : ''
        })
    })

Serverside is VBScript/ASP.

some_code is a textbox with following text: someValue čšžćđ that needs to be saved just like that.

When scanning network traffic (IE9) I see this: some_code=someValue Äšžćđ

When looking in the database (Oracle 12c) I see this: someValue ?????

Html page encoding is Windows-1250. NLS_LANG and NLS_CHARACTERSET are Slovenian.

I've tried out advice from at least a dozen different links, but to no avail, so I'm turning to you guys and girls. Thank you!

Robotronx
  • 1,728
  • 2
  • 21
  • 43
  • 2
    If you are sending the content as `UTF-8` then the asp page also needs to be `UTF-8` otherwise you will get an encoding mismatch. What links have you tried, not this one I'd wager... [Answer to Convert UTF-8 String Classic ASP to SQL Database](http://stackoverflow.com/a/21914278/692942) *(read it carefully)* – user692942 Aug 19 '14 at 11:25
  • @Lankymart Tried it, but it didn't work. Messed up all the encoding that did work. I have to mention that when I open the page, čšđžć diacritics show correctly. It's only when I try to POST them, are they saved incorrectly. I tried the stored procedure on its own, it saves correctly, so it's bound to be something on the page itself. – Robotronx Aug 19 '14 at 12:49
  • When you say you *"tried it*" what did you try, I guarantee that this will be your issue I've delt with this over and over again and people say *"I've tried it"* but usually they miss something. Remember the page that saves to the database has to also save in the correct encoding this means both the page itself and the responses have to be the correct encoding, there is no quick fix. It would help if you showed the code for the page that saves the data to the database. – user692942 Aug 19 '14 at 12:54
  • Your answer mentions EACH page should be saved in UTF-8 format. This is not an option for me. I'm not allowed to do that. All of our pages are encoded in ASCII (Notepad++). How is it possible to display diacritics correctly, but not to save them? All of our pages are in ASCII and they save diacritics correctly, except this one. – Robotronx Aug 19 '14 at 13:05
  • It doesn't have to be `UTF-8` that just gives you the best support for multiple character sets. If you specify a codepage that supports the diacritics then you are ok, but if you wonder outside that codepage and wonder why it's not working then I'd say read a book. – user692942 Aug 19 '14 at 13:18
  • PAges themselves display in `charset=Windows-1250`. Files are saved in ASCII. We have at least a hundred different .asp files that operate the way they should, but this one just refuses, even though everything is the same (at least as far as I know). Guess I'm wrong... – Robotronx Aug 19 '14 at 13:30
  • So why is your ajax call posting the data as `contentType: "charset=utf-8"` if all your pages are `Windows-1250`? – user692942 Aug 19 '14 at 13:39
  • It's the only allowed format. I didn't find a way to transform text encoding from 1250 to utf-8 so a properly encoded text can be transmitted. – Robotronx Aug 19 '14 at 13:47
  • Sorry you've lost me why not specify `contentType: "charset=windows-1250"` in your ajax call if your page `someUrl.asp` is encoded in `windows-1250`, why do you need to transform the text? – user692942 Aug 19 '14 at 13:49
  • JSON allows only UTF-8. Somewhere along the line the diacritics get screwed. – Robotronx Aug 19 '14 at 13:54
  • If the JSON has to be `UTF-8` then set that page to `<% @CodePage="65001" %>` and `<% Response.Charset = "UTF-8" %>` then save the actual file `someUrl.asp` as `UTF-8` **not** `ASCII`. – user692942 Aug 19 '14 at 13:59

1 Answers1

0

Right from the comments think I understand the issue;

The JSON has to be sent as contentType: "charset=utf-8" so the page someUrl.asp will also need to process in UTF-8 to do this follow the below steps.

Based on your comment have made some changes to the below code.

  1. First re-save the someUrl.asp file using UTF-8 encoding not ASCII.

  2. Set the first line in someUrl.asp to;

    <%@Language="VBScript" CodePage = 65001 %>
    
  3. Then add the following lines;

    <%
    Response.Charset = "Windows-1250"
    Response.CodePage = 1250
    %>
    

Note: When making changes always remember to save the file with UTF-8 encoding.

Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
  • Did everything you said, but its even worse now, because text that was previously displayed correctly is not messed up too. – Robotronx Aug 19 '14 at 14:59
  • @Robotron If that is the case then there is something else wrong with your text, you need to be clear on what you are passing in (encoding wise) and what you expect back out. This works so if you are having problems it's because you are doing something that you haven't explained. – user692942 Aug 19 '14 at 15:01
  • @Robotron Try changing `Response.Charset = "Windows-1250"` and `Response.CodePage = 1250` that should process the `UTF-8` input but output it as `Windows-1250`. If you still have problems are you sure `Windows-1250` supports the diacritics you want to display? – user692942 Aug 19 '14 at 15:11