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



首先,请原谅我的英语。。。我解释我的问题:我有一些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按钮吧。当您单击该按钮时,表单将被提交。这就是上面捕捉到的事件。打字要小心,有很多打字错误!

相关内容

最新更新