This might be a simple question but I have not yet found the way to sort it out. I would like to download csv file from server (implemented by ASP.NET Web API) by ajax call:
$.ajax({
type: "GET",
accepts: "text/csv; charset=utf-8",
url: "/api/employees",
success: function (data) {
}
});
I have put the Accepts header in jQuery ajax like above. But from fiddler, I see:
The Accepts header now turns to Accept: undefined
. If I try to put:
accepts: {
csv: "text/csv; charset=utf-8"
}
The Accepts Header now turns to: Accept: */*
So I guess that is the main point to make my server returns JSON object rather than CSV file.
How can I make Accepts Header in jQuery ajax correctly? and see in the fiddler should be:
Accept: text/csv
I am using Chrome.
try
$.ajax({
headers: {
Accept : "text/csv; charset=utf-8",
"Content-Type": "text/csv; charset=utf-8"
}
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With