top

XMLHttpRequest : overrideMimeType on 2012 platform

Published 2014-10-27 | (Compatible with SDK 3.5,4.5,5.0,5.1 and 2012,2013,2014 models)

XMLHttpRequest : overrideMimeType on 2012 platform

If response is not null AND Content-Type is present in XML response, and XHR Response MimeType is not set (i.e. ‘text/xml’, ‘application/xml’) then it returns a null as response.

Solution

Add overrideMimeType to XHR Request.

Bad example

xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.send(null);

Good example

var xhr = new XMLHttpRequest();
if (xhr.overrideMimeType) {
xhr.overrideMimeType('text/xml');
}
xhr.open("GET", url, true);
xhr.send(null);

See also

W3C XMLHttpRequest
XHR reference.