2
votes

I'm trying to force an 'ISO-8859-1' charset on my ajax request header but for some reason I can't get it to change from "UTF-8". I've got the following...

var request = new Request({
    url: url,
    method: 'post',
    data: params,
    encoding: 'ISO-8859-1',
    onSuccess: function(textResponse, xmlResponse) {
            //success func
        },
        onFailure: function(xhr) {
            //fail func
        }
    }).send();

Even after configuring that setting, my Request Header's content-type shows "application/x-www-form-urlencoded; charset=UTF-8" in Chrome's Developer Tools.

Any ideas?

1

1 Answers

1
votes

It does work. 1 tiny problem: the code path for setting the charset is behind another variable - urlEncoded: true needs to be set.

see https://github.com/mootools/mootools-core/blob/master/Source/Request/Request.js#L175-L178

and a jsfiddle to demo this: http://jsfiddle.net/dimitar/3qazx/

new Request({
    url: '/echo/html/',
    data: {
        html: '<p>Text echoed back to request</p>',
        delay: 0
    },
    method: 'post',
    urlEncoded: true,
    encoding: 'ISO-8859-1',
    onComplete: function(){
        $('target').set('html', this.response.text);
    }
}).send();

I'd argue the documentation is unclear of the relation between the two - http://mootools.net/docs/core/Request/Request#Request

it says it but meh:

  • urlEncoded - (boolean: defaults to true) If set to true, the content-type header is set to www-form-urlencoded + encoding
  • encoding - (string: defaults to utf-8) The encoding to be set in the request header.

the latter needs 'ignored when urlEncoded not true'