如何使用html按钮发送POST请求 [英] How to send POST request using html button

查看:1308
本文介绍了如何使用html按钮发送POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用html按钮发送帖子请求。我知道这是很容易做的jQuery ajax,但我不想使用jquery和ajax。我该怎么办呢?

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?

这是我的函数

public function editProduct() {
    if($_SERVER['REQUEST_METHOD'] === 'POST') {
        echo 'You are authorized';
    } else {
        echo 'You are not authorized to access this page.';
    }
}

这是我的HTML按钮

<button type="submit" onclick="location.href = '<?=base_url().'company/admin/add_product/editProduct?>';">Send Post Request</button>


推荐答案

post

<form method="post">
 ...
    <button type="submit" >
</form>

这篇关于如何使用html按钮发送POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆