0

can some one look at the code and tell me, what Am i doing wrong here? At send, I am getting 400 error.Method downlaodPDF is not even hit.Here is my code.

   $('#downloadPDF').on('click', function () {        
    var token = $("input[name='__RequestVerificationToken']").val();
    var vehicle = { "fname": "henry", "lname": "ford" };
    var dataJson = JSON.stringify(vehicle);        
    var req = new XMLHttpRequest();
    req.open("POST", "/Test?handler=DownloadPDF");
    req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");      
    req.send(dataJson);

    req.responseType = "blob";
    req.onload = function (event) {
    var blob = req.response;
    console.log(blob.size);
    var link=document.createElement('a');
    link.href=window.URL.createObjectURL(blob);
    link.download="Report_" + new Date() + ".pdf";
    link.click();  };    

});

  public void OnPostDownloadPDF([FromBody]ReportInput input)
    {
       //My code here
        HttpContext.JsReportFeature().Recipe(Recipe.ChromePdf);

    }
Swetha
  • 1
  • 1
  • What parameters are required by the server? – rleir Jan 29 '20 at 14:43
  • What do you see in Chrome debugger? (right click, select inspect) – rleir Jan 29 '20 at 14:44
  • I was able to fix the issue by adding the plugin mentioned here https://stackoverflow.com/questions/53437849/download-of-jquery-ajax-request-contents-is-empty  https://github.com/acigna/jquery-ajax-native – Swetha Jan 30 '20 at 16:05

0 Answers0