Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use POST with an HTML5 download attribute?

As of HTML5, in some browsers , I can use the download attribute on anchor directives:

   <a href="my-site.com/read_me.txt" download>

I can even parameterize it:

   <a href="my-site.com/secret.php?user=me&password=letmein" download>

But maybe I want some privacy.

is there any conceivable way to use POST, rather than GET?

If not, I will obfuscate the parameters. I am 99% sure that it can't be done, and want someone to add the last 1% to that.

like image 985
Mawg says reinstate Monica Avatar asked Jan 17 '17 15:01

Mawg says reinstate Monica


1 Answers

No you can't force an anchor element to do a POST request; It's always GET.

for a POST request, you must submit a form:

common javascript style:

<a onclick="document.getElementById('form_id').submit();">click here</a>

using jquery:

$(function() {
  $("#anchor_id").on("click",function(e) {
    e.preventDefault();
    $.post(this.href,function(data) {
      // callback function
    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
like image 199
armezit Avatar answered Sep 21 '22 23:09

armezit