How can I change the default encoding used by $.post()
?
The arguments are encoded with UTF-8. How can I encode it with ISO 8859-1?
See section 4.5.6.4.4.3 of the XHR spec: https://xhr.spec.whatwg.org/#the-send()-method
If contentTypeRecord is not failure, contentTypeRecord’s parameters["charset"] exists, and parameters["charset"] is not an ASCII case-insensitive match for "UTF-8", then:
Set contentTypeRecord’s parameters["charset"] to "UTF-8".
The spec forces browsers to always send as UTF-8.
You may however, use the fetch
API. Since it's not an XHR, posting using fetch will honour your encoding.
fetch(url, {
method: 'POST',
headers: {
'Content-Type': `text/plain; charset=${yourCustomEncoding}`
},
body
}).then(...