我在模板中有一个符号形式:
Template.php
<form class="well" action="<?php echo url_for("@submitParam?param=".$con) ?>" method="post">
<input type="text" name="param">
<button type="submit" class="thisBtn">Button</button>
</form>
按下提交按钮时,如何使用jquery、javascript或任何其他方式(symfony或者php)将值从HTML输入name="param"
传递到url或变量$con
?
更新:你也可以使用AJAX:
$(".btn").live('click', function(){
$.post("<?php echo url_for('@submitParam'); ?>", $('.box').serialize(), function(response) {
switch(response.status) {
case 'success':
console.log("Success");
break;
case 'failure':
console.log("Failure");
break;
}
}, 'json');
return false;
});
操作:
$request->getParameter('param');
要在url中发送param
值,请使用提交按钮
<input type="submit" class="thisBtn" value="button"/>
并改变获取的方法
method="get"
为什么要这样做?您已经有了param
的值,因为它是表单中的一个输入元素。