Is it possible to submit POST data to a PHP script using only jQuery, without a form on the page and with page refresh?
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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.