3

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.

acoder
  • 667
  • 2
  • 9
  • 19

1 Answers1

1

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

WWZee
  • 494
  • 2
  • 8
  • 23