I want to download MS Word file with an AJAX post request.
So here is my Java code
 response.setContentType("application/ms-word");
 response.setHeader("Content-Disposition", "attachment; filename="+childName+".docx");
 OutputStream opStream = response.getOutputStream();
The service name is "/getAdmissionAgreement" and it is post request. Now this is how I am downloading the file using ajax post request:
$.ajax({
    type: "POST",
    url: url,   
    cache: false,
    success: function (response) {
        alert('got response');
        window.open(response);
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert('Error occurred while opening fax template' + getAjaxErrorString(textStatus, errorThrown));
    }
});
Now the problem is that the stream is coming but it is getting displayed in the browser's console and not coming as an downloadable file.
 
     
    