go to another page with POST via a

I have a page base.html where i go at index.php with a link:

<a id="goTo" href="#">go to...</a>

So, i need to send at index.php a POST message like param='myValue' using the jQuery library. I have try use this script:

<script type="text/javascript">
$(document).ready(function(){
    $('#goTo').click(function() {
        event.preventDefault(); 
        alert('Ok!');
        $.ajax({
            method: 'POST',
            data: 'param=MyValue'
            url: 'index.php',
        });
    });
});
</script>

But does not work as i want. How i can do?

Edit I need to go into index.php and not remain in base.html .

Answers


How about this for the data?

data: { param: "MyValue" },

<script type="text/javascript">
$(document).ready(function(){
    $('#goTo').click(function() {
        event.preventDefault(); 
        alert('Ok!');
        $.ajax({
            method: 'POST',
            data: { param: "MyValue"},
            url: 'index.php',
        });
    });
});
</script>

Since you want to actually take the user to index.php:

You could have a form with appropriate action and method:

<form id="theForm" action="index.php" method="post">
    <input type="hidden" name="param" value="MyValue" />
</form>

And then submit the form:

$('#goTo').click(function (e) {
    e.preventDefault();
    $('#theForm').submit();
});

Or you could put a button in the form and let the html do the work for you:

<form action="index.php" method="post">
    <input type="hidden" name="param" value="MyValue" />
    <input type="submit" value="Submit" />
</form>

Need Your Help

DataFrame frequency infos

python pandas

Is there a mean to extract automatically the count of observation by hour ?

SCTP RCVBUF is not set properly in Linux

linux sctp

I am trying to set RCVBUF to 1MB//1048576 , But after setting the value when I am trying to read it through getsockopt it always gives the value as 2MB//2097152