How do I use javascript so that the browser can download the generated file?

0

I have a server app that returns an xls file, and from javascript I make the POST call, so that when I return the file, hide the gif of "loading ..." and allow the browser to download the file. If I do $ ("#respuestas_form") .submit (); it works perfect, but I can not hide the gif of "loading ..." So I used the following but it does not work for me:

$.ajax({
  type: 'POST',
  url: $('#respuestas_form').attr('action'),
  data: {
    'csrfmiddlewaretoken': '{{ csrf_token }}',
	'encuesta_id': $( "#encuesta_id" ).val(),
  },
  success: function(result){
    $("#div_cargando").hide();
	$( "#errors" ).html("");
	var contentType = "application/ms-excel";
	var filename = "marcelo.xlsx"
	//var attachment = "attachment";
	//var blob = new Blob([result], { type: contentType, Content-Disposition: attachment });
	return new File([result], filename, {type: contentType, lastModified: Date.now()});
	//window.open(filename);

  }
});

How should I do so that the browser allows me to download the file?

    
asked by marcelo schiavone 07.06.2018 в 17:05
source

0 answers