是否可以通过超链接使用POST方法传递值? [关闭]

Is it possible to make a form submit POST style with an anchor?

<form>
    <input name="foo" />
    <input name="bar" />

    <a href="#">Submit this form</a>
</form>

Original question, also gets explained in this answer by Martijn

Is it possible to pass a value using hyperlink as a POST method ?? i want to pass a value on clicking an image to the next page.

Im going to leave my original answer below, why an anchor can not perform a post call. However, the question has been rephrazed, this answer will answer that question:

You can not use a anchor to submit, but its somewhat common practice to make it trigger a submit:

$('a#myAnchor').click(function(){ $('#myForm').submit() })
/// Or an image, doesn't really matter for jQuery:
$('img#myImg').click(function(){ $('#myForm').submit() })
// Or native js:
document.getElementById('myImg').onclick = function(){ document.getElemetById('myForm').submit() });

if the element you want to trigger a submit with is inside of a form:

$('element').click(function(){ $(this).closest('form').submit() });

No. Anchors are GETbecause anchors send you to an url, which makes it GET, never POST.

POST is data being send in post-format, it gets encoding in a way the server can handle it (important for images and such)

In this other topic this reply explains difference between GET and POST

If you must, and I mean REALLY must, you could use jQuery to fake a post, something allong these lines:

// THIS IS AN UNTESTED DRAFT! Just to shown you a direction:
$('a').click(function(e){
    e.preventDefault();
    var scriptname = this.href.replace(/\??(.*)?/, ''); // remove everything after '?'
    var query     = this.href.replace(/(.*)\?/, ''); // remove everything before '?'
    $.post(scriptname, query);
});

But again, DONT DO THIS, unless you really REALLY have to. This will send a ajaxcall to the server, so the page wont actually change. Because this is bad practise, im not gonna show you how to make the page change on completion, you'll have to figure this out with the jQuery POST documentation