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 badges2 Answers
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
版权声明:本文标题:javascript - Character encoding issue when loading a div using jQuery.load() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744918221a2632126.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论