开发者

Character encoding issue when loading a div using jQuery.load()

I am loading a html page to a div using jquery AJAX load. The loaded page has german characters, and is not encoded correctly开发者_JAVA技巧, 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.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/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.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/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


 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜