Luc
Luc

Reputation: 17072

accent not showing in jQuery load

I'm working on a small site that I would like to change a little bit so it is more dynamic. The index .html is something like

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
...
</head>
<body>
    <div id="page">
        <div id="header"></div>
        <div id="main">
            <div id="menu"></div>
            <div id="content"></div>
        </div>
        <div id="footer"></div>
    </div>
</body>
<html>

I use jQuery and for example I load a "menu.html" file in the "menu" div. Menu.html is something like:

<ul>
    <li><a id="item1">item 1</a></li>
    <li><a id="item2">item 2</a></li>
</ul>

With JQuery I have added some code so that when clicking on the "item1" link then a item1.html file is loaded in the "content" div. This works fine except that I do not get any accents from menu1.html (I have some '?' instead).

The item1.html is something like:

Hello, this is my file
c'est un <strong>fichier</strong> avec des accents à, é

I do not have any html, body tags in those files (there are only there in the index.html).

Could you please help ?

Thanks a lot,

Luc

Upvotes: 1

Views: 3518

Answers (4)

Raul
Raul

Reputation: 1

Something similar happened to me. I was loading the content of an txt file into a div and kind of ? appeared instead of spanish characters á, é, í, ó and ú.

I solved it changing the encodig of this text file a UTF-8

Upvotes: 0

kojoru
kojoru

Reputation: 807

This looks like encoding problems.

Is your item1.html encoded by iso-8859-1? Is your web server configured to include iso-8859-1 into headers of a web page? Do accents work in your main file if placed there? Try to check that encodings in every file are the same and sent correctly.

If that doesn't work you can also try switching the whole project to utf-8. There is almost no reason for using iso these days especially in non-english projects.

Pat's answer will probably work for you quickly, but will not solve the underlying issue and will complicate the creation of new pages.

Upvotes: 1

Walid
Walid

Reputation: 88

if using Internet Explorer, did you try View / Encoding and checking 'Autoselect'.

do you get the same issue with other browsers?

Upvotes: 0

Pat
Pat

Reputation: 25675

You'll need to encode the accented characters. I would try HTML entites first:

é = &eacute;
à = &agrave;

If that doesn't work, you can use unicode encoding:

é = \u00e9
à = \u00e0

Upvotes: 3

Related Questions