Ajax response is gzip compressed - Prototype, Fire

2019-07-09 13:26发布

问题:

I'm trying to query a web service (with JavaScript, prototype). The server responds with XML, but compresses it; headers are set appropriately.

Under Safari 4, everything is fine. The response is decompressed and JavaScript can deal with the data.

Under Firefox 3.5.8, no data is returned to JavaScript!

Code:

     var req = new Ajax.Request(this.url, {
        asynchronous: false,
        contentType: 'text/xml',
        method: 'post',
        postBody: xmlString,
        onSuccess: function(t) {
            // debug, place response into textarea to show
            $('responseText').value = t.responseText;
        }
    });

This is the response, as I trace it on the network:

HTTP/1.1 200 OK.
Date: Fri, 05 Mar 2010 14:10:51 GMT.
Server: Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny6 with Suhosin-Patch.
X-Powered-By: PHP/5.2.6-1+lenny6.
Vary: Accept-Encoding.
Content-Encoding: gzip.
Content-Length: 2104.
Keep-Alive: timeout=15, max=100.
Connection: Keep-Alive.
Content-Type: text/xml.
.
............]s......W`.3...H&A.$.Q.^[.:....... (and so on ...)

Any idea why this is happening? What can I do about it?

I tried setting the 'Accept-Encoding' header in the request, can't get it working properly. Besides, the response can be rather large, meaning: it's good that it is compressed by the server.