问题
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.
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!
回答1:
Solved using ajax for every tab request and writing again my code.
来源:https://stackoverflow.com/questions/31709225/update-select-list-without-refresh-pdo-php-ajax