admin管理员组

文章数量:1406710

I am loading a html page to a div using jquery AJAX load. The loaded page has german characters, and is not encoded correctly, while the german characters in the main page is displayed correctly. Somebody please help me with this issue.

HTML Page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-15"/>
<script type="text/javascript" src="script/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
 $.ajax({
 url : 'startPage.html',
 dataType: 'text',
 contentType: "application/x-www-form-urlencoded;charset=utf-8",
 success : function(data){
           $('#loadPage').html(data);
           }
 });

});
</script>
</head>
<body>
<div id="loadPage"></div>
<br />
Länge Länge
</body>
</html>

code for startPage.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-15"/>
</head>
<body>
Loaded Content - Länge - (This text is not displayed correctly)
</body>
</html>

In This page I event tried adding the meta tags for iso encoding, still without any success. Please help

I am loading a html page to a div using jquery AJAX load. The loaded page has german characters, and is not encoded correctly, while the german characters in the main page is displayed correctly. Somebody please help me with this issue.

HTML Page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-15"/>
<script type="text/javascript" src="script/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
 $.ajax({
 url : 'startPage.html',
 dataType: 'text',
 contentType: "application/x-www-form-urlencoded;charset=utf-8",
 success : function(data){
           $('#loadPage').html(data);
           }
 });

});
</script>
</head>
<body>
<div id="loadPage"></div>
<br />
Länge Länge
</body>
</html>

code for startPage.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-15"/>
</head>
<body>
Loaded Content - Länge - (This text is not displayed correctly)
</body>
</html>

In This page I event tried adding the meta tags for iso encoding, still without any success. Please help

Share asked Mar 28, 2011 at 18:30 SullanSullan 1,1572 gold badges24 silver badges39 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5
 beforeSend : function(xhr) {
        xhr.overrideMimeType('text/html; charset=iso-8859-15');
    },

Use this within your ajax function, or ajaxSetup();

You need to make sure all your charset are declared the same way in order to display correctly. In example, you get:

<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-15"/>

While asking for:

contentType: "application/x-www-form-urlencoded;charset=utf-8",

Make sure you know which one you want and give the right charset. The encoding of your .html, .php and .js documents is also a factor of errors. If you'Re using notepad++ or any editors of code, make sure you encoded your files with the same charset you want them to display. I suggest you "convert" your files so that you dont loose all special caracters you already put in there.

本文标签: javascriptCharacter encoding issue when loading a div using jQueryload()Stack Overflow