0

Im using this code:

$(document).ready(function () {
    var breadCrumps = $('.breadcrumb');
    breadCrumps.find('span').text("<%= ArticleSectionData.title %>");
});

title is a property which has values encoded in unicode (I think). These are Greek letters. On the local IIS developer server (embedded in visual studio), the characters are displayed in correct way but, on the test server they appear as:

&#931;

Do You know any solution for this problem ?

Thanks for help

EDIT:

I have changed the code a little bit:

breadCrumps.find('span').text(<%= ArticleSectionData.title %>);

And now it works correctly, encoding is frustrating ...

5
  • Please use .text() instead to avoid XSS. Commented Sep 29, 2011 at 20:45
  • how text is going to avoid XSS ? Im getting data from the server so I think there is no need for doing that. In fact with /html it works correctly while with .text it fails on encoding Commented Sep 29, 2011 at 20:48
  • .html sets the innerHTML. If ArticleSection.title is based on user-input, and they made a title of <script>somethingbad</script> - then you are going to execute the script. .text() will display the actual script because the script tag will be escaped. Commented Sep 29, 2011 at 20:55
  • Ok, but the content doesnt depend on the user. Admin inserts it to the database Commented Sep 29, 2011 at 21:04
  • Wait, which is it? It works in dev, but not test? Or, it works with .html(), but not .text()? Commented Sep 29, 2011 at 21:54

2 Answers 2

3

If you are working off of a different database in test than in dev, then I suspect the issue is with the data. If you are storing HTML entities (eg, &#931;) in your database, then you need to use .html(). If you are storing actual unicode characters (eg, Σ) in the database, then you need to use .text(). The way to represent Σ in html is with &#931;. But if you set the text of an element to &#931;, it displays that literally - the innerHTML of that element would contain &amp;#931;.

Sign up to request clarification or add additional context in comments.

2 Comments

"If you are storing actual unicode characters (eg, Σ)." How can I know if Im storing unicode characters or HTML entities? What is the difference in the way databse holds these two options ?
@gruber - The string "&#931;" is not meaningful to a database - Ie, it doesn't represent a unicode character within the database - it only represents a unicode character in HTML, XML, etc. So, either your database is storing the HTML entity string "&#931;" or it is storing the actual unicode character "Σ". Just do a SELECT myField FROM myTable and look at the output to see which it contains. You'll see either "Σ" or "&#931;".
0

I don't know root of problem, but you can use this http://www.strictly-software.com/htmlencode for decode &#931; to Sigma

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.