繁体   English   中英

将变量从js发布到表单,然后发布到php文件

[英]Post variables from js to form and then to php file

首先,打招呼,请原谅我的英语...我解释我的问题:我有一些生成某些变量的JS函数,我想通过POST方法将这些变量发送到要在数据库中查询的php文件。我已经读到,做到这一点的最佳方法是将变量发送到表单中有关输入的各个值,下面我展示了变量和表单:

Javascript变量:在“ Buscar”中单击

            $('#Buscar').on('click', function () {
            document.getElementById("tipo").value=TipoDeInmuebleDATA.selectedData.value;
            document.getElementById("operacion").value=TipoDeOperacionDATA.selectedData.value;
            document.getElementById("habitaciones").value=HabitacionesDATA.selectedData.value;
            document.getElementById("MetrosCuadrados").value=MetrosCuadrados;
            document.getElementById("banos").value=BanosDATA.selectedData.value;
            document.getElementById("precio").value=Precio;
});

表格:

        <form name="FormBuscar" method="post" action="consulta.php">
            <input id="tipo" name="tipo" type="hidden" />
            <input id="operacion" name="operacion" type="hidden" />
            <input id="MetrosCuadrados" name="MetrosCuadrados" type="hidden" />
            <input id="habitaciones" name="habitaciones" type="hidden" />
            <input id="banos" name="banos" type="hidden" />
            <input id="precio" name="precio" type="hidden" />
            <input type="submit" name="Buscar" class="BotonBuscar">
        </form>

我怀疑有问题,就我而言,如果我执行以下操作,则认为变量没有发送给咨询人员:

$tipo=$_POST['tipo'];
echo $tipo;

没有结果 :-(

问候,我将等待您的答复!

该事件是错误的。 您要在提交前立即更改值。 因此,还要在表单标签中添加id="buscar-form" 然后,您可以将jQuery更改为此:

$('#buscar-form').on('submit', function () {
  $('#tipo').val(TipoDeInmuebleDATA.selectedData.value);
  $('#operacion').val(TipoDeInmuebleDATA.selectedData.value);
  ...
});

忘记#buscar按钮。 当您单击按钮时,表单将提交。 这就是上面捕获的事件。 小心输入,有很多错别字!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM