如何通过jQueryMobile 1.3.1中的AJAX在正确的字符编码中加载ISO-8859-1内容? [英] How to load ISO-8859-1 content via AJAX in jQueryMobile 1.3.1 with correct character encoding?
问题描述
为了可视化移动设备上的数据,我使用jQuery Mobile 1.3.1。一般来说,如果您在HTML中使用正确的元标记,那么字符编码没有问题:
< meta charset = iso-8859-1/>
但是jQuery Mobile已经有了这个默认设置:
$。mobile.ajaxEnabled = true;
所以,如果可能,jQuery Mobile将自动处理链接点击并通过Ajax表单提交。
这是一个非常聪明的功能,但它破坏了一些特殊字符,如德语umlaute,你会得到这个讨厌的字符:
问题是jQuery Mobile 1.3.1在ajax请求上使用默认的UTF-8。
有不同的解决方案来解决问题:
-
禁用特定链接的Ajax,重定向到特殊的内容字符:
data-ajax =false
-
完全关闭ajax预加载功能:
$。 .ajaxEnabled = false;
-
按照建议,并手动设置正确的内容类型并覆盖mime类型:
$。ajaxSetup {
contentType:'application / x-www-form-urlencoded; charset = ISO-8859-1',
beforeSend:function(jqXHR){
jqXHR.overrideMimeType('application / x -www-form-urlencoded; charset = ISO-8859-1');
}
});
最后一个解决方案为我工作。 / p>
I have got a PHP script (CMS) which generates ISO-8859-1 content (in the background there is also a database with Latin1 data). To visualize the data on mobile devices I use jQuery Mobile 1.3.1. In general there is no problem with character encoding if you use the correct meta tag in your HTML:
<meta charset="iso-8859-1" />
However jQuery Mobile has got this default setting:
$.mobile.ajaxEnabled = true;
So jQuery Mobile will automatically handle link clicks and form submissions through Ajax, when possible.
This is a very smart feature, but it destroys some special characters like german umlaute and you get this nasty characters: �
The problem is that jQuery Mobile 1.3.1 uses on default UTF-8 on ajax requests. There are different solutions to solve the problem:
Disable Ajax for specific links, which redirect to content with special characters:
data-ajax="false"
Turn off completely the ajax preloading feature:
$.mobile.ajaxEnabled = false;
Follow this recommendation and manually set the correct content type and override the mime type:
$.ajaxSetup({ contentType: 'application/x-www-form-urlencoded; charset=ISO-8859-1', beforeSend: function(jqXHR) { jqXHR.overrideMimeType('application/x-www-form-urlencoded; charset=ISO-8859-1'); } });
The last solution did work for me.
这篇关于如何通过jQueryMobile 1.3.1中的AJAX在正确的字符编码中加载ISO-8859-1内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!