I am facing an issue in sending an ajax get request to download a file served by a REST API in java.
The REST api
@GET
@Path("/{modelName}/export")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
The API is working fine. The problem is with my ajax call
$.ajax({
type: "GET",
url: serverUrl+'/api/models/'+modelName+'/export',
success : function(res){
alert("success");
console.log(res);
},
error : function(res){
alert("error");
console.log(res);
}
});
When this call is executed I need the file to be downloaded. How do I modify the ajax call in order to that?
i am getting a success alert when I execute it, and some random strings are printed in the console.