I'd like to open my js file genereted by a microservice (byte[]):
public int getLabel(Request request, Response response) throws IOException {
response.header("Access-Control-Allow-Origin", "*");
ArrayList<JSONObject> orders = createListOfJSONObjects(request.queryParams("orders"));
response.header("Content-Type", "application/pdf");
ServletOutputStream outputStream = response.raw().getOutputStream();
outputStream.write(createPDF(orders));
outputStream.flush();
outputStream.close();
return 200;
}
I'd like to have the response by ajax:
$("#printlabels").click(function() {
var jsonData = $(this).data().ordersJson;
console.log(jsonData)
$.ajax({
// type: GET,
async: true,
url: "http://localhost:60000/api/create-label",
data: {orders: jsonData},
success: function(resp){
???;
}
});
});
I want my browser to open or save the pdf file