Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having issues sending ® character through AJAX request

I have simple asp.net web application which is using YUI for Ajax request. Application read text from text box and send AJAX request to server. Following is the code

<body>
    <form id="form1" runat="server">
    <div>
        <input id="txt" name="txt" type="text" value="[Enter some value]" />
        <input id="btn" type="button" value="button" />
    </div>
    <div id="out"></div>
    </form>
</body>

following is the client script that initializes the Ajax request

YAHOO.util.Event.onDOMReady(function() {
    YAHOO.util.Event.addListener("btn", "click", function(evt) {
        var url = "Server.aspx?type=test&txt=" + document.getElementById("txt").value;
        var btn = document.getElementById("out");
        var cObj = YAHOO.util.Connect.asyncRequest('GET', url, {
            success: function(o) {
                btn.innerHTML += "<div>" + o.responseText + " = " + o.responseText.charCodeAt(0) + "</div>";
            },
            failure: function(o) {
                confirm("Its failure");
            },
            cache: false
        });
    });
});

What i do in application is accept character entered by user, save it to db and write it to Ajax response. System does not support Unicode (database).

Now my problem is that when "Registered" ® character (0174) is entered in the text box and sent to server i am getting #65533 which is not what user has entered on the text box. Also ® this character is not Unicode character then why this behavior.

like image 285
Anil Namde Avatar asked Dec 05 '11 14:12

Anil Namde


2 Answers

Forget about configuration issues, your problem is probably related to your editor and the file encoding it's using to save your files. It's not enough to set the character encoding, sometimes it doesn't even matter, you have to save the files themselves in an encoding thats supports the character set, for example: utf-8 without BOM, get an editor where you can see this information. Of course there could be a lot happening between in your web server, data base server(assuming you are using one) and client. Checkout the default character in the whe web server, the database and the file encoding your editor is using to save the files.

like image 176
Puerto AGP Avatar answered Sep 23 '22 18:09

Puerto AGP


Deducing from the tags you set, the backend is programmed in asp.net? Check what encoding you are working with there (see e.g. here). Your problem sounds a lot like that would differ from what you deliver to the client (see server settings).

like image 36
codeling Avatar answered Sep 23 '22 18:09

codeling