HTML表单
<script >
$(function(){
$("#location").autocomplete({
source: "<?php echo SITE_ROOT;?>xyz/signup/autocomplete"
});
});
</script>
AJAX
function autocomplete()
{
if (isset($_GET['term'])){
$city = strtolower($_GET['term']);
$this->registration_model->get_location($city);
}
}
控制器
function get_location($city)
{
$this->db->select('name');
$this->db->like('name', $city);
$this->db->limit('6');
$query = $this->db->get('cities');
if($query->num_rows() > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row['name']));
}
echo json_encode($row_set);
}
}
模型
this.appservice.getData().subscribe(data => this.data = data);
问题:当用户输入城市名称时,如何在城市名称后显示自动填写的州名和国家名称? 此代码的输出: 如果你在文本框中键入s,这段代码会给出6个名字,其中后者是。