javascript - In jQuery, how to http get a gzip file? -


i run simple http server myself, using node.js , express.js.

var express = require('express'); express().use(express.static(__dirname)).listen(3000); 

in static content folder, there 2 files testing purposes: myfile.csv , myfile.csv.gz. sizes 685 , 403 bytes, respectively. used curl -i view response header. content-length field correctly reflects file size.

curl -i http://localhost:3000/myfile.csv  http/1.1 200 ok x-powered-by: express accept-ranges: bytes etag: "685-1377648449000" date: wed, 28 aug 2013 11:12:40 gmt cache-control: public, max-age=0 last-modified: wed, 28 aug 2013 00:07:29 gmt content-type: text/csv; charset=utf-8 content-length: 685 connection: keep-alive  curl -i http://localhost:3000/myfile.csv.gz  http/1.1 200 ok x-powered-by: express accept-ranges: bytes etag: "403-1377677249000" date: wed, 28 aug 2013 11:12:48 gmt cache-control: public, max-age=0 last-modified: wed, 28 aug 2013 08:07:29 gmt content-type: application/octet-stream content-length: 403 connection: keep-alive 

then write below javascript code snippet in order fetch 2 files in client browser. correctly alerts 685, size of myfile.csv.

$.ajax({     type: 'get',     url: "myfile.csv",     datatype: "text",     success: function (result) {         alert(result.length);     }, }); 

however, when change url field myfile.csv.gz, script alerts 387 instead of 403. cannot full content of myfile.csv.gz. what's wrong?

i tried changing datatype "text" "application", encountered "parse error" saying "no conversion text application."

i tried adding headers: { "accept-encoding": "gzip" }, encountered error saying "refused set unsafe header "accept-encoding"".

how can full content of gzip file using jquery in client browser?

i have figured out solution myself. add mimetype: "application/octet-stream; charset=x-user-defined" , go.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -