How can I store and retrieve British pound symbols?

This is a problem that I encounter every so often; I always end up writing some kind of terrible site, but I'm sure there must be a proper way to deal with it (in the end, of course, it is not uncommon to want to work with British pound characters).

Problem: user enters UK pound symbol ( Β£) in a text box in CMS. They click save, and the form field value is escaped using the JavaScript function escape()and sent using the jQuery AJAX request POST. However, at some point, the pound symbol becomes a question mark (incorrect character encoding?).

I can’t just convert the character to its HTML object before saving it to the database, because when the values ​​are retrieved for display on the front side of the website, they are encoded in HTML format (so the object will just display as).

To solve this for me once and for all, what should I do here?

+3
source share
3 answers

You do not need to use the function escape. jQuery already handles the encoding:

$.ajax({
    url: '/somepage',
    data: { param1: $('#textfield').val() },
    success: function() { }
});

Just make sure your application is configured for UTF-8 encoding:

<system.web>
    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>

And the HTML pages also:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+4
source

form field value is reset using JavaScript escape () function

. escape - URL , , . encodeURIComponent, . escape - , ASCII, Β£.

jQuery, , POST ; {x: 'Β£'}, .

, Β£, . UTF-8 UTF-8 IO, Darin, NATIONAL (NVARCHAR) Unicode SQL Server.

HTML , , -, HTML

! . HTML- , . HTML- , .

+2

Try to keep the pound symbol of the UK as the pound; so that when displayed in the html response, the UK pound symbol is displayed.

0
source

Source: https://habr.com/ru/post/1722562/


All Articles