Jquery ignores encoding ISO-8859-1

前端 未结 2 674
名媛妹妹
名媛妹妹 2020-11-29 10:24

I have a website which apperently removes the correct encoding (ISO-8859-1) from a string and sends it wrong.

I have this encoding specified in my HTML



        
相关标签:
2条回答
  • 2020-11-29 11:02

    Because I had the same problem, I'll provide a solution that worked for me. Background: Microsoft Excel is too stupid to export a CSV-File in charset UTF-8:

    $.ajax({
        url: '...',
        contentType: 'Content-type: text/plain; charset=iso-8859-1',
        // This is the imporant part!!!
        beforeSend: function(jqXHR) {
            jqXHR.overrideMimeType('text/html;charset=iso-8859-1');
        }
    });
    
    0 讨论(0)
  • 2020-11-29 11:07

    According to the jQuery.ajax() contentType documentation:

    Data will always be transmitted to the server using UTF-8 charset; you must decode this appropriately on the server side."

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