Reputation: 29
everything works, I get my json array returned in an alert, I just need to change the onSubmit event handler $('#city').submit(function()
to something more dynamic that grabs the user input and runs the ajax call as soon as the user types the letters.
Upvotes: 0
Views: 100
Reputation: 1888
I'd recommend the keyup() event:
$("#term").keyup(function(e){
});
But you can also use the autocomplete function from JQuery-UI: autocomplete
Using autocomplete this would be:
$("#term").autocomplete({source: "/suggestjson", minLength: 2, select: function (event, ui) {
//do something when the user selects, by the way the value
//selected by the user is in: 'ui.item.value'
}});
Upvotes: 1
Reputation: 3097
Use
$('#city').change(function() {
var formdata = $('#term').val()
$.ajax({
url: "/suggestjson",
type: "GET",
dataType: "json",
data: {'term': formdata},
success: function (data) {
alert(data);
}
});
return false;
});
Or
$('#city').keyup(function() {
........
.......
});
Upvotes: 0