问题
I want to send post request using html button. I know it is easily done by jQuery ajax, but i do not want to use jquery and ajax. How can i do it?
This my function
public function editProduct() {
if($_SERVER['REQUEST_METHOD'] === 'POST') {
echo 'You are authorized';
} else {
echo 'You are not authorized to access this page.';
}
}
This is my HTML button
<button type="submit" onclick="location.href = '<?=base_url().'company/admin/add_product/editProduct?>';">Send Post Request</button>
回答1:
In your form tag, just write a method="post"
<form method="post">
...
<button type="submit" >
</form>
回答2:
You have two ways to do this:
via form (best method):
<form action ="<?php echo base_url().'company/admin/add_product/editProduct'?>" method="post"> <input type="submit" value="Send Post Request"> </form>
via javascript (jquery: http://api.jquery.com/jquery.post/ )
来源:https://stackoverflow.com/questions/30864319/how-to-send-post-request-using-html-button