Can I use POST with an HTML5 upload attribute?

As in HTML5, in some browsers , I can use the download attribute in binding 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 need privacy.

Is there any conceivable way to use POST, not GET?

If not, I will confuse the options. I am 99% sure that this is impossible, and I want someone to add the last 1% to it.

+4
source share
1 answer

No, you cannot force the anchor element to execute a POST request; He is always get.

for a POST request, you must submit the form:

general 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>
Run codeHide result
+1

Source: https://habr.com/ru/post/1667025/


All Articles