Click here to attend Spring Framework 4.x and certification course with a discount

//city list
$("input#location").autocomplete({
width: 300,
max: 10,
delay: 0,
minLength: 1,
autoFocus: false,
cacheLength: 1,
scroll: true,
highlight: false,
source: function(request, response) {
$.ajax({
type : "POST",
url: "<%=request.getContextPath()%>/cityList.k",
dataType: "json",
data: "cityName=" + $("input#location").val(),
success: function( data, textStatus, jqXHR) {
$("#nav").val('c');
$("#validated").val('0');
//console.log( data.idCity);
var items = data;
//jQuery.each(data, function(i, val) {
//response(val.idCity);
//});
response(items);
},
error: function(jqXHR, textStatus, errorThrown){
alert("Error contact@kameroom.nl");
}
});
}, close: function (event, ui) {
//alert('close' +this.value);
//alert('selected');
return false;
},
select: function (event, ui) {
$("input#location").val(ui.item.cityName);
$("input#idCity").val(ui.item.idCity);
$("#cityError").hide();
$("#validated").val('1');
//alert('selected');
return false;
},
focus: function(event, ui) {
//$("input#place").val(ui.item.cityName);
return false;
}
}).data("autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.cityName + "</a>")
.appendTo(ul);
};
@RequestMapping(value="/cityList.k", method=RequestMethod.POST)
public @ResponseBody List<City> cityList(
@RequestParam("cityName") String cityName,
ModelMap model, HttpServletRequest request) throws Exception {
List<City> cityList = locationManager.cityList(cityName);
return cityList;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s