I'm not sure if this is even possible. But I was wondering if anyone knows how to make a hyperlink pass some variables and use POST (like a form) as opposed to GET.
相关问题
- Views base64 encoded blob in HTML with PHP
- Angular RxJS mergeMap types
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
This is an old question, but none of the answers satisfy the request in-full. So I'm adding another answer.
The requested code, as I understand, should make only one change to the way normal hyperlinks work: the
POST
method should be used instead ofGET
. The immediate implications would be:href
POST
I am using jquery here, but this could be done with native apis (harder and longer of course).
And to see the result, save the following as reflector.php in the same directory you have the above saved.
You don't need JavaScript for this. Just wanted to make that clear, since as of the time this answer was posted, all of the answers to this question involve the use of JavaScript in some way or another.
You can do this rather easily with pure HTML and CSS by creating a form with hidden fields containing the data you want to submit, then styling the submit button of the form to look like a link.
For example:
The exact CSS you use may vary depending on how regular links on your site are styled.
This is not possible using raw HTML, although you could use jQuery to add a click event handler to the link that could use the post function to issue the POST.
Check this it will help you
You can use this jQuery function
Here is an example in jsFiddle (http://jsfiddle.net/S7zUm/)
You create a form with hidden inputs that hold the values to be posted, set the action of the form to the destination url, and the form method to post. Then, when your link is clicked, trigger a JS function that submits the form.
See here, for an example. This example uses pure JavaScript, with no jQuery — you could choose this if you don't want to install anything more than you already have.