title: ajax response as pdf, how to show it?
body: <p>I have a web service that generate a pdf. In my GAE application I have a button, when i click i use an ajax's function.</p>
  
  <pre><code>$('#test').click(function(){
          $.ajax({
              url: 'provaws.do',
              type: 'get',
              dataType: 'html',
                      success : function(data) {
                      }
          });
      });
  </code></pre>
  
  <p>this is the method in java that's call ws, using UrlFetch:</p>
  
  <pre><code>    @RequestMapping(method = RequestMethod.GET, value = PROVAWS_URL)
  public void prova(HttpServletRequest httpRequest, HttpServletResponse httpResponse, HttpSession httpSession) throws IOException{
      try {
          URL url = new URL("http://XXXXX/sap/bc/zcl_getpdf/vbeln/yyyyyy");
          HttpURLConnection connection = (HttpURLConnection) url.openConnection();
          connection.setRequestProperty("Authorization","Basic " + Base64.encodeBase64String(("username:password").getBytes()));
          connection.setConnectTimeout(60000);
          if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
              // OK
              ByteArrayOutputStream bais = new ByteArrayOutputStream();
              InputStream is = null;
              try {
                is = connection.getInputStream();
                byte[] byteChunk = new byte[4096];
                int n;
  
                while ( (n = is.read(byteChunk)) &gt; 0 ) {
                  bais.write(byteChunk, 0, n);
                }
              }
              catch (IOException e) {
  
              }
              finally {
                if (is != null) { is.close(); }
              }
              httpResponse.setContentType("application/pdf");
              httpResponse.setHeader("content-disposition","attachment; filename=yyyyy.pdf");             
              httpResponse.getOutputStream().write(bais.toString().getBytes("UTF-8"));
              httpResponse.getOutputStream().flush();         
          }
  ....
  }
  </code></pre>
  
  <p>With Firebug i see the repsonse:</p>
  
  <pre><code>%PDF-1.3
  %âãÏÓ
  2 0 obj
  &lt;&lt;
  /Type /FontDescriptor
  /Ascent 720
  /CapHeight 660
  /Descent -270
  /Flags 32
  /FontBBox [-177 -269 1123 866]
  /FontName /Helvetica-Bold
  /ItalicAngle 0
  ....
  </code></pre>
  
  <p>What i need to set in ajax's function to show the pdf?</p>
  
  <p>Thanks in advance</p>