这是我的代码
$('#txt_street').typeahead({
autoSelect:false,
ajax: {
url: "/index.php/MyCities/get_myCities/",
timeout: 500,
async : false,
displayField: "city_name",
valueField: 'city_id',
triggerLength: 1,
method: "get",
loadingClass: "loading-circle",
preDispatch: function (query) {
return {
search: query
}
},
preProcess: function (data) {
return data;
}
},
onSelect: function (citySelect) {
} //on select end
}); //city typeahead ends
我有两个问题:
答案 0 :(得分:3)
您可以在preDispatch
中添加其他参数并在致电typeahead()
之前创建 ajax 网址
获取更多信息:
myUrl = "http://yoursite.com/" + yourdata; //Here your custom url
$('#txt_street').typeahead({
autoSelect:false,
ajax: {
url: myUrl , // Your custom url
timeout: 500,
async : false,
displayField: "city_name",
valueField: 'city_id',
triggerLength: 1,
method: "get",
loadingClass: "loading-circle",
preDispatch: function (query) {
return {
search: query,
otherParam: 123 //Other parameter get you want
}
},
preProcess: function (data) {
return data;
}
},
onSelect: function (citySelect) {
} //on select end
}); //city typeahead ends