1

I have the following html being returned in my $.ajax call:

"<div class="quiz-result-preview">
    <div class="responseText">
    </div>
    <div class="wrong-answered-questions">
        <div class="questionDiv">
            <span class="text-red">1. </span> <h4>Penicillin er ett annet navn for antibiotika</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">3. </span> <h4>Om jeg er forkj&amp;oslash;let blir jeg raskere frisk av &amp;aring; spise antibiotika.</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">4. </span> 
            <h4>N&#229;r en person er syk er det best &#229; ta den type antibiotika som dreper flere ulike bakterier, ikke bare en.</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">5. </span> <h4>Det er farlig &amp;aring; drikke alkohol samtidig som jeg spiser penicillin.</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">7. </span> <h4>
                Det spiller ikke s&#229; stor rolle hvilket antibiotika jeg f&#229;r, s&#229; lenge det dreper bakterien som gj&#248;r meg syk.</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">8. </span> <h4>
                Antibiotika hemmer eggl&#248;sningen og reduserer mulighetene for &#229; bli gravid.</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">10. </span> <h4>
                Un&#248;dvendig bruk av antibiotika p&#229;virker bare samfunnet i form av resistente bakterier - ikke meg som person.
            </h4>
        </div>
    </div>
</div>
"

As you can see there are some special characters eg. Un&#248; , now when i append the above html to my result div , like so:

$('#resultTemp').html(data);

The special characters display as is, how do i instead display the correct characters ?

3
  • See this, you might have to decode the character before appending: stackoverflow.com/questions/7885096/… Commented Jul 4, 2018 at 11:34
  • 1
    Possible duplicate of Decode HTML entities in JavaScript? Commented Jul 4, 2018 at 11:36
  • 1
    It appears some of the entities are being double encoded, ie &amp;aring; instead of &aring; you would need to decode them at least once before inserting, or fix them being double encoded Commented Jul 4, 2018 at 11:41

1 Answer 1

1

Use correct encoding.

<head>
  <meta charset="UTF-8">
</head>

<head>
  <meta charset="UTF-8">
</head>

<div class="quiz-result-preview">
    <div class="responseText">
    </div>
    <div class="wrong-answered-questions">
        <div class="questionDiv">
            <span class="text-red">1. </span> <h4>Penicillin er ett annet navn for antibiotika</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">3. </span> <h4>Om jeg er forkj&amp;oslash;let blir jeg raskere frisk av &amp;aring; spise antibiotika.</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">4. </span> 
            <h4>N&#229;r en person er syk er det best &#229; ta den type antibiotika som dreper flere ulike bakterier, ikke bare en.</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">5. </span> <h4>Det er farlig &amp;aring; drikke alkohol samtidig som jeg spiser penicillin.</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">7. </span> <h4>
                Det spiller ikke s&#229; stor rolle hvilket antibiotika jeg f&#229;r, s&#229; lenge det dreper bakterien som gj&#248;r meg syk.</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">8. </span> <h4>
                Antibiotika hemmer eggl&#248;sningen og reduserer mulighetene for &#229; bli gravid.</h4>
        </div>
        <div class="questionDiv">
            <span class="text-red">10. </span> <h4>
                Un&#248;dvendig bruk av antibiotika p&#229;virker bare samfunnet i form av resistente bakterier - ikke meg som person.
            </h4>
        </div>
    </div>
</div>

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.