JQuery post without form but with page refresh

Is it possible to post POST data to a PHP script using only jQuery, no form on the page and no page refresh?

Redirecting

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

      

This example is sending GET data, but how can I send POST data with this redirect?

POST

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

      

This example will not refresh the page.

+3


source to share


1 answer


You can make the form hidden to have the data in the form and then "submit it" yourself.

if you included

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 send things via message, but not show them

+2


source







All Articles