I am getting error while downloading and opening pdf files as
Failed to load PDF document
. But when i tried to download txt file it gets download success fully. I need to this ajax request to be as POST method, So after searching in internet i found this code.
$.ajax({
type: "POST",
url: url,
cache: false,
contentType: false,
processData: false,
success: function (data) {
    var blob = new Blob([data]);
    var link = document.createElement('a');
    link.href = window.URL.createObjectURL(blob);
    link.download = textName;
    link.click();
}, error: function (data) { alert("error"); }});
I use web api for downloading the file
public HttpResponseMessage Download(string fileName)
{   
    string filePath = Path.Combine(PATH, fileName.Replace('/', '\\'));
    byte[] pdf = System.IO.File.ReadAllBytes(filePath);
    HttpResponseMessage result = Request.CreateResponse(HttpStatusCode.OK);
    result.Content = new ByteArrayContent(pdf);
    result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
    result.Content.Headers.ContentDisposition.FileName = "MyPdf.pdf";
    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
    return result;
}
Please help me
 
     
     
    