I recently switched from Apache to nginx and had the same problem. Everything worked fine when downloading as simple files or from an Apache server, but responseXML
always empty when running on nginx.
In my specific situation, an XSL stylesheet was also used to transform the XML:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="main-template-transformer.xsl"?>
The content type of a regular XML file was returned just fine. However, the content type of the XSL file was important. (This was discovered by checking the responseText
, which was not null, and contained the entire text of the XSL file. Checking the HTTP headers in this file showed that the content type was changed between Apache and nginx.)
The content type must be either text/xml
or application/xml
. The default value in nginx 1.10.3 is application/octet-stream
, and this will cause responseXML
to always be zero.
This can be fixed by adding the following line to the JavaScript file:
xmlhttp.overrideMimeType('text/xml');
This can be fixed by adding the following line to the nginx server configuration in "conf / mime.types":
text/xml xsl;
source share