使用jquery在表单提交上添加post变量值

I have to send some POST variables with values when submitting the form. I have to send variable_1 and variable_2

In result.php I need to get the value of $_POST['variable_1'] and $_POST['variable_2']. How can I do this?

<form action="result.php" method="post">      
  <input type="submit" name="submit">
</form>
$('form').submit(function () { 
  var variable_1 = "test";
  var varible_2 = "test2";       
});

Please help.

i got the answer for my question

$('form').submit(function () {
    var input = $("<input>")
                   .attr("type", "hidden")
                   .attr("name", "variable_1").val("test1");
    var input_2 = $("<input>")
                   .attr("type", "hidden")
                   .attr("name", "variable_2").val("test2");
    $('form').append($(input));
    $('form').append($(input_2));
});

I achieve what you need using the below.

Add a form and tag with an id. Add a standard button for submitting the form.

   <form id="frMyForm" method="post">      
        <input id="btnSubmit" type="button" name="submit">
    </form>

Next capture the submit buttons click event, append the extra info to the form, then post the form data to the desired Controller/Action.

$(document).on("click", "#btnSubmit", function () {
    //Serialize Form
    var myData = $('#frMyForm').serialize();

    //Append custom value
    var variable_1 = "test";
    myData = myData + "&var1=" + variable_1; //You could get this from a hidden field perhaps.

        $.ajax({
            type: "POST",
            url: "/Controller/Action",
            data: myData
        });
    });

Hope that helps

You can Use These :

<form action="result.php" method="post">
      <input type="hidden" name="variable_1" value="test">
      <input type="hidden" name="variable_2" value="test2">
      <input type="submit" name="submit">
    </form>