public
Created

XmlHttpRequest w/ compression support

  • Download Gist
ajax-call-with-compression.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
// typical generic request routine (handles GET and POST)
function makeRequest(href, next, body, contentType) {
var ajax;
 
ajax=new XMLHttpRequest();
if(ajax) {
 
ajax.onreadystatechange = next();
 
if(body) {
ajax.open('post',href,false);
ajax.setRequestHeaders('content-type',contentType);
ajax.setRequestHeaders('accept-encoding','gzip');
ajax.send(body);
}
else {
ajax.open('get',href,false);
ajax.setRequestHeaders('accept-encoding','gzip');
ajax.send(null);
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.