i Have a problem with download file by jquery.
I have a post function that send request in the java code.
I return the file but this doesn't download.
Input
<input type="button" id="export-csv" value="Export result in CSV"/> Html-jquery Code
$( "#export-csv" ).click(function( ) { var request=$.ajax({ method: "POST", url: 'user/writeCsv', data: $( "#search-form" ).serialize(), dataType: "text/csv" }).done(function(data) { window.location.href = (data); }); // $.post( "user/writeCsvToReturn", $( "#search-form" ).serialize()) }); Java code
@RequestMapping(value="/user/writeCsv",method=RequestMethod.POST) public FileWriter writeCSVFile(HttpServletResponse response,ServerSearchCommand ssc, Model model, BindingResult result) throws IOException { FileWriter fileWriter= new FileWriter("/tmp/searchcsv.csv"); fileWriter.flush(); //WRITE DATA FILE fileWriter.close(); return fileWriter; }