sql >> Database >  >> RDS >> Mysql

Hoe de vervolgkeuzelijst te vernieuwen zonder paginavernieuwing?

Gebruik jQuery Ajax

uwbestand.php

<select id="location" onchange="getState(this.value)" name="location" class='form-control'>
<option value="0">Select location</option>
    <?php
        $query = mysql_query("select * from city");
            while($row = mysql_fetch_assoc($query))
            {
                echo '<option value="'.$row['cityid'].'">'.$row['cityname']. '</option>';
            }
    ?>
</select>

<select id="state">

</select>

JQuery-script

function getState(city_id)
{
    var html = $.ajax({
        type: "POST",
        url: "path/to/ajax/my_ajax.php",
        data: "city_id=" +city_id,
        async: false
    }).responseText;
    if(html){
        $("#state").html(html);
    }
}

AJAX.php

$query = mysql_query("select * from state where city_id=".$_REQUEST['city_id']);
            while($row = mysql_fetch_assoc($query))
            {
                echo '<option value="'.$row['state_id'].'">'.$row['state_name']. '</option>';
            }



  1. postgresql en pgadmin starten in Windows zonder installatie

  2. Hoe kan ik een zoekopdracht detecteren die de vergrendeling in Postgres bevat?

  3. Wat betekent <> in Oracle

  4. MySQL-update of hernoem een ​​sleutel in JSON