【问题标题】:jQuery post without a form but with page refresh没有表单但页面刷新的 jQuery 帖子
【发布时间】:2015-07-07 16:09:26
【问题描述】:

是否可以仅使用 jQuery 将 POST 数据提交到 PHP 脚本,页面上没有表单并且页面刷新?

重定向

$(document).ready(function(){
    $('.button').click(function(){
        window.location.replace('index.php?some_value=1');
    });
});

在这个例子中,发送的是 GET 数据,但是如何通过这种重定向发送 POST 数据?

发布

$(document).ready(function(){
    $('.button').click(function(){
        $.post(
            'index.php',
            {
                some_value: '1'
            }, function(result) {
                alert(result);
            }
        );
    });
});

这个例子不会刷新页面。

【问题讨论】:

标签: php jquery post http-post


【解决方案1】:

您可以隐藏表单,以便将数据包含在表单中,然后自己“提交”。

如果你包含

style="display:none"

像这样在你的表单中

<form style="display:none" action="POST">
    <input field your input field>
    <input maybe another input field>
</form>

那么您仍然可以通过帖子提交内容,但不会显示

【讨论】:

    猜你喜欢
    • 2017-07-16
    • 2013-02-14
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多