Update select list without refresh [PDO/PHP/AJAX]

非 Y 不嫁゛ 提交于 2020-01-05 21:06:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!