How to load ISO-8859-1 content via AJAX in jQueryMobile 1.3.1 with correct character encoding?

后端 未结 1 939
广开言路
广开言路 2021-01-16 09:16

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

相关标签:
1条回答
  • 2021-01-16 09:45

    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.

    0 讨论(0)
提交回复
热议问题