jQuery $.get() charset of reply when no header is set?

前端 未结 3 1002
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 13:45

I just recently installed Winamp Song Requester wich is a Winamp web song requester plugin with a built in minimal HTTP CGI Server.

What the plugin does is that it r

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 14:12

    edit: ok i think this works (at least it worked in my test environment, see revisions for previous attempt)

    $.ajaxSetup({
        'beforeSend' : function(xhr) {
            xhr.overrideMimeType('text/html; charset=UTF-8');
        },
    });
    $('#stuff').load('/yourresource.file'); // your ajax load
    

    what i had was the main file set in UTF-8 and the data file set in ISO-8859-1. without the above code, i got a bunch of garbage for the test string åäöé, as expected. with the above code, it loaded åäöé properly encoded.

提交回复
热议问题