1

right now, my function looks like this

    scope.downloadCsv = function(){
         $http.({
          method:'POST',
          url:'php/crud.php',
          data:scope.postPayload,
          headers:{'content-type':'application/x-www-form-urlencoded'} 
          }).success(function(){console.log("download done!")});
     };

I've tried binding that button to an ng-click, ng-submit, and following the instructions on Download text/csv content as files from server in Angular (which works, but not on Firefox).

I don't know the technical term, but I'm assuming I somehow needs to be able to click on a link with a "POST" request, that way the browser thinks it's not an ASYNC call, I just don't know how to accomplish it. It has to be a post because I'm passing a bunch of data to the server to operate on to generate the CSV. Any help is GREATLY Appreciated!

Community
  • 1
  • 1

1 Answers1

2

You cannot download a file with ajax. My 1st choice would be to just create a normal html form, to post to a hidden iframe:

<form method="post" action="php/crud.php" target="hidden_iframe">
<input type="hidden" name="data" value="{{postPayload}}">
<button type="submit">Download!</button>
</form>
<iframe name="hidden_iframe"></iframe>
Steve
  • 20,703
  • 5
  • 41
  • 67
  • ajax v/s normal form is good, but is there any method to use ng-click and html form side by side? – Ranvir Oct 07 '15 at 04:49