Reputation: 229
For example, suppose I'm using AJAX to send a request to a server like so:
$.ajax(
{
url: url,
beforeSend: function (request) { request.setRequestHeader('X-Test', 'one'); },
});
The documentation for $.ajax
contains the following:
contentType (default: 'application/x-www-form-urlencoded; charset=UTF-8') Type: String
When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding.
According to this, the default is UTF-8, but I'm not clear from the description if the contentType
header affects only the encoding of the request's body or the encoding of the other headers as well (if the latter can even be changed).
Upvotes: 2
Views: 1787
Reputation: 582
You have to remember that AJAX render part of the HTML body, so when you send data in a AJAX request with some content type, for example iso-8859-1, the data is setting with that content type only in the AJAX request life cycle.
I hope my answer be useful for you.
Good lucky.
Upvotes: 0