I defined a part of my RESTful API to return a JSON or Excel list of data, based on the Accept
in the request. For the JSON version it is easy to use with Ajax (jQuery):
$.ajax({
url: api.url.measurement,
contentType: "application/json",
dataType: "json",
success: function(result) {
console.log(result.data);
}
});
But, how would I make the browser download the result to a file, when using application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
as Accept
? I cannot just use a a
element, because I have to provide a header.