开发者

Dealing with ISO-encoding in AJAX requests (prototype)

开发者 https://www.devze.com 2022-12-28 20:05 出处:网络
I have a HTML-page, that\'s encoded in ISO-8859-1 and a P开发者_运维知识库rototype-AJAX call that\'s build like this:

I have a HTML-page, that's encoded in ISO-8859-1 and a P开发者_运维知识库rototype-AJAX call that's build like this:

new Ajax.Request('api.jsp', {
    method: 'get',
    parameters: {...},
    onSuccess: function(transport) {
        var ajaxResponse = transport.responseJSON;
        alert(ajaxResponse.msg);
    }
});

The api.jsp returns its data in ISO-8859-1. The response contains special characters (German Umlauts) that are not displayed correctly, even if I add a "encoding: ISO-8895-1" to the AJAX-request. Does anyone know how to fix this?

If I call api.jsp in a new browser window separately the special characters are also corrupt. And I can't get any information about the used encoding in the response header. The response header looks like this:

Server  Apache-Coyote/1.1
Content-Type    application/json
Content-Length  208
Date    Thu, 29 Apr 2010 14:40:24 GMT

Notice: Please don't advice the usage of UTF-8. I have to deal with ISO-8859-1.


Just found the answer myself. Though this is for PHP I'm sure you can find the equivalent for ASP :)

Basically, just include the encoding header on your response page (in your case api.asp), like this:

header("Content-Type: text/html; charset=ISO-8859-1");

Good luck with it :)

//Jannik Olsen

0

精彩评论

暂无评论...
验证码 换一张
取 消