1

Until now I foolishly thought JavaScript's encodeURI() would produce the same results as ASP classic's Server.URLEncode(). Here's an example where that fails:

encodeURI("戦艦帝国") = "%E6%88%A6%E8%89%A6%E5%B8%9D%E5%9B%BD"
Server.URLEncode("戦艦帝国") = "%C6%88%A6%C8%89%A6%C5%B8%9D%C5%9B%BD"

Since I'm in a system that uses both languages, is there any encoding method in one that is guaranteed to produce the same encoding as a method in the other?


(Note: Server.UrlEncode(str) is supposedly equivalent to HttpUtility.UrlEncode(str, Response.ContentEncoding))

4
  • I tried to convert the result, but the javascript one seems wrong. meyerweb.com/eric/tools/dencoder Commented Oct 19, 2016 at 14:34
  • @Vixed - Both that tool and this tool match the javascript value (i.e., the one beginning %E6). Probably because they're using javascript.... Commented Oct 19, 2016 at 14:49
  • <%=server.UrlEncode("戦艦帝国")%> returns %E6%88%A6%E8%89%A6%E5%B8%9D%E5%9B%BD I think it's just a question of charset. Commented Oct 19, 2016 at 14:56
  • @Vixed - You're right! My ASP page is getting the string from an MS SQL database. It displays it correctly (as pasted here), but there must be something else tagging along with the string value that produces the different encoding in that scenario. Digging back in now..... Commented Oct 19, 2016 at 15:16

1 Answer 1

1

This works for me, but be sure to save using UTF-8

<%Response.charset="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
    </head>
  <body>
    <%=Server.UrlEncode("戦艦帝国")%>
    <br />
    <script>document.write(encodeURI("戦艦帝国"))</script>
  </body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

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.