donmqryh49993 2018-06-28 13:13
浏览 383
已采纳

使用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.

  • 写回答

3条回答 默认 最新

  • duanjing9339 2018-06-28 13:52
    关注

    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));
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样