如何通过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?

查看:185
本文介绍了如何通过jQueryMobile 1.3.1中的AJAX在正确的字符编码中加载ISO-8859-1内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本(CMS)生成ISO-8859-1内容(在后台还有一个数据库,拉丁文数据)。
为了可视化移动设备上的数据,我使用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。
有不同的解决方案来解决问题:


  1. 禁用特定链接的Ajax,重定向到特殊的内容字符:

      data-ajax =false


  2. 完全关闭ajax预加载功能:

      $。 .ajaxEnabled = false; 


  3. 按照建议,并手动设置正确的内容类型并覆盖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:

  1. Disable Ajax for specific links, which redirect to content with special characters:

    data-ajax="false"
    

  2. Turn off completely the ajax preloading feature:

    $.mobile.ajaxEnabled = false;
    

  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆