JQuery - descargar file jquery

 
Vista:

descargar file jquery

Publicado por download file jquery y servlet (1 intervención) el 17/10/2014 08:24:14
inicialmente genere un servlet que me genera un archivo excel y se descarga de forma automatica a traves del navegador ,el incoveniente viene cuando ahora necesito llamar al servlet a traves de jquery pero el archivo ya no se descarga .
Espero su ayuda y se agradece su apoyo de antemano

Adjunto ttrozo del servlet("GenerarArchivo") donde se genera el archivo en excel (utilizo libreria apache poi)
1
2
3
4
5
6
excel2007 x = (excel2007) imp;
Workbook libro = x.getLibro();
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment;filename=" + repo.getNOMARC() + ".xlsx");
libro.write(response.getOutputStream());
response.getOutputStream().close();

codigo de javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<script type="text/javascript">
            $(document).ready(function() {
                $("#generar").click(function(e) {
                    e.preventDefault();
                    var btn = $(this);
                    btn.button('loading');
                    var dataString = $('#myform').serialize();
                    alert(dataString);
                    $.ajax({
                        type: "POST",
                        url: "GenerarArchivo",
                        data: dataString,
                        error: problemas,
                        success: function(data) {
                           $("#resultado2").html("se genero");
                        }
                    }).always(function() {
                        btn.button('reset')
                    });
                    ;
                });
            });
            function problemas() {
                alert("ERROR");
            }
        </script>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder