title: Loading GZIP JSON file using AJAX
body: <p>I have gzipped json file using below algorithm (from:  <a href="https://stackoverflow.com/questions/7564138/java-gzip-cant-keep-original-files-extension-name">java gzip can&#39;t keep original file&#39;s extension name</a>)</p>
  
  <pre><code>private static boolean compress(String inputFileName, String targetFileName){
           boolean compressResult=true;
           int BUFFER = 1024*4;
           byte[] B_ARRAY = new byte[BUFFER]; 
           FileInputStream fins=null;
           FileOutputStream fout=null;
           GZIPOutputStream zout=null;
           try{
               File srcFile=new File(inputFileName);
               fins=new FileInputStream (srcFile);
               File tatgetFile=new File(targetFileName);
               fout = new FileOutputStream(tatgetFile);
               zout = new GZIPOutputStream(fout);
               int number = 0; 
               while((number = fins.read(B_ARRAY, 0, BUFFER)) != -1){
                   zout.write(B_ARRAY, 0, number);  
               }
           }catch(Exception e){
               e.printStackTrace();
               compressResult=false;
           }finally{
               try {
                  zout.close();
                  fout.close();
                  fins.close();
              } catch (IOException e) {
                  e.printStackTrace();
                  compressResult=false;
              }
           }
           return compressResult;
      }
  </code></pre>
  
  <p>I am returning the JSON</p>
  
  <pre><code>response.setHeader("Content-Type", "application/json");
  response.setHeader("Content-Encoding", "gzip");
  response.setHeader("Vary", "Accept-Encoding");
  response.setContentType("application/json");
  response.setHeader("Content-Disposition","gzip");
  response.sendRedirect(filePathurl);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>request.getRequestDispatcher(filePathurl).forward(request, response);
  </code></pre>
  
  <p>Trying to access the JSON object using AJAX code as below:</p>
  
  <pre><code>$.ajax({
      type : 'GET',
      url : url,
      headers : {'Accept-Encoding' : 'gzip'},
      dataType : 'text',
  </code></pre>
  
  <p>The output I see is the binary data, not the decompressed JSON string. Any suggestion on how to make this work?
  Note that the Browsers I am using (IE, Chrome, FF) supports gzip as all my static contents which are gzipped by Apache are rendered correctly.</p>