问题描述
我正在使用引导程序,并且创建了将数据插入数据库的teo选项卡,但是第一个选项卡具有一个选择列表,该列表将加载使用第二个选项卡中的表单插入的数据.问题是我无法在不刷新页面的情况下填写第一个选项卡中的选择列表.我在stackoverflow和Google搜索中尝试了无数解决方案,但没有人起作用.
I'm using bootstrap and i've created teo tabs that insert data into database, but the first tab have a selection list that loads data inserted using the form in the second tab.The problem is that i can't fill the selection list in the first tab without refreshing the page.I've tried inumerous solutions here in stackoverflow and googling but no one worked.
这是表单和php的代码:
Here is the code of the form and php:
<form class='form-horizontal' role='form' action="index.php" method="post" id="nl_0" name="nl_0">
<div class='form-group'>
<label class='control-label col-md-2 col-md-offset-2' for='id_accomodation'>Tipo de Produto</label>
<div class='col-md-2'>
<select class='form-control' id='id_accomodation' name="id_accomodation" onchange="this.form.submit();">
<?php
try
{
$db = new PDO("pgsql:host=localhost dbname=blablabla user=postgres password=*****");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("SELECT * FROM taxes ORDER BY type");
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$options .= "<option>" . $row{type} . "</option>";
}
}
catch(PDOException $e)
{
echo "Error:". $e->getMessage();
}
?>
<?php echo $options;?>
</select>
</div>
</div>
唯一不起作用的是没有刷新的自动更新.任何帮助我都会非常感谢!
The only thing that doens't work is the auto update without refresh.Any help i will be very thankfull!
推荐答案
对于每个选项卡请求,均使用ajax解决,然后再次写入我的代码.
Solved using ajax for every tab request and writing again my code.
这篇关于更新选择列表而不刷新[PDO/PHP/AJAX]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!