[英]jQuery post without a form but with page refresh
Is it possible to submit POST data to a PHP script using only jQuery, without a form on the page and with page refresh? 是否可以仅使用jQuery将POST数据提交到PHP脚本,页面上没有表单并且页面刷新?
Redirection 重定向
$(document).ready(function(){
$('.button').click(function(){
window.location.replace('index.php?some_value=1');
});
});
In this example GET data is sent, but how can I send POST data with this redirection? 在此示例中,将发送GET数据,但如何使用此重定向发送POST数据?
POST POST
$(document).ready(function(){
$('.button').click(function(){
$.post(
'index.php',
{
some_value: '1'
}, function(result) {
alert(result);
}
);
});
});
This example will not refresh the page. 此示例不会刷新页面。
You could make the form hidden so as to have the data within a form and then "submit it" yourself. 您可以隐藏表单,以便在表单中包含数据,然后自己“提交”。
if you include 如果你包括
style="display:none"
in your form like this 在你的形式这样
<form style="display:none" action="POST">
<input field your input field>
<input maybe another input field>
</form>
then you can still submit things via post but not have it show up 然后你仍然可以通过邮寄提交但没有显示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.