send $_POST data via anchor tag

后端 未结 4 1327
夕颜
夕颜 2021-01-07 16:00

is it possible to somehow send $_POST[] data via a tag? because it seems to automaticly execute the $_POST[] once the page l

相关标签:
4条回答
  • 2021-01-07 16:09

    Answer is no. What you can do is set the value of an input type when the <a> tag gets clicked. Using Javascript.

    0 讨论(0)
  • 2021-01-07 16:21

    You could get hold of the query string from the href attribute of the anchor tag (you would need to parse the href and get hold of the string on the right hand side of the & symbol) and then post it using javascript or jquery (easier to use jquery).

    http://api.jquery.com/jquery.post/

    Would have to ask why you would want/need to do this?

    0 讨论(0)
  • 2021-01-07 16:32

    You can achieve this using jQuery and a HTML form

    HTML:

    <form method="post" name="redirect" class="redirect">
    <input type="hidden" class="post" name="post" value="">
    <input type="submit" style="display: none;">
    </form>
    

    Button: (html)

    <a href='javascript:void(0)' class='button' var='DATAHERE'>sometexthere</a>
    

    Javascript, or rather said jQuery:

    $(".button").click(function() {
        var link = $(this).attr('var');
        $('.post').attr("value",link);
        $('.redirect').submit();
    });
    

    this jQuery code listen's to any clicks on the items with the class button attached to them, and reads out their "var" value, basicly you could use any kind of HTML element using this method as long as they have the button class attached to it.

    0 讨论(0)
  • 2021-01-07 16:32

    Nothing in HTML will cause a link to trigger a POST request or encode data in the request body.

    You can bind a JavaScript event handler to a link, cancel the default behaviour and then send a POST request by programmatically submitting a form or using XMLHttpRequest. This generally isn't a good idea and you should use a submit button instead (which you can style to look like a link if you really, really want to).

    0 讨论(0)
提交回复
热议问题