[英]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.