Ajax Error - Question marks on sending Foreign Language

Yup! So that’s the problem when you switch to Foreign Languages! This post is related to my previous post – A Forgotten Story – Ajax in ASP.NET using JavaScript.

Last day, I’s trying to send Chinese characters over the wire through Ajax. Surprisingly, I received every Chinese characters at the server-side as questions marks.

A mock-up looks like:


After spending few hours with the academic basics, the problem was pin-pointed.

The request sending from the client-side was not encoded, which was the reason for this weird behavior. I slightly modified the Ajax code to encode the value from the TextBox and the problem was solved!

You can use either of the below JavaScript function to achieve it:

  1. encodeURI

    This function is used to encode URI. It encodes special characters (except / , ? : @ & = + $ #)
  2. encodeURIComponent

    This function encodes URI component, including the characters excluded by encodeURI

And, a modified code-segment looks like


Hope there is no question-marks in your Request.

Happy Encoding!