【发布时间】:2016-06-19 16:32:00
【问题描述】:
我正在使用 Laravel 制作一个 Web 应用程序,其中一部分是用户指定他们的居住地。当他们在国家/地区选择中选择一个国家时,使用 AJAX 使用该国家/地区的州填充州输入(“下拉菜单”)。当他们选择一个州时,它使用 AJAX 用该州的城市填充城市输入(“下拉菜单”)。世界上有如此多的州和城市,州和城市的 mySQL 表将根据用户的输入来填充。
如何使用 Laravel 和 jQuery 进行选择/下拉/自动完成输入,以允许 1)用户根据先前选择的值从存储在数据库中的值列表中选择一个选项,以及 2)添加一个新值如果没有呢?
下面是我尝试将国家和州的输入链接在一起:
//get id of country selected, AJAX to database and return an array of it's states
$("#country_id").change(function(){
var country_id = $(this).val();
$.ajax({
url:base_url + "/locations/stateJSON",
data:{country_id:country_id},
success: function(states) {
//console.log(states);
}
});
});
//state's input is text input jQuery autocomplete populated with selected country's states
$("#state_id").autocomplete({
source: states,
minLength: 1
});
【问题讨论】:
标签: javascript jquery jquery-ui laravel laravel-4