When I browse, in stackoverflow itself I could find so many questions like this. Still asking.. as I couldnt get any idea.
if ($.trim(location).length > 2) {
var randomNum = Math.floor(Math.random() * 9999999999999);
var url = "/mobile/App/GetLocations?noCache=" + randomNum + "&h="
+ location;
$('#' + smartFillBoxId).empty();
$('#' + smartFillBoxId).hide();
$.ajax({
url:url
}).done(
function (data) {
selectedLocation = htmlData = "";
var count = 0;
results = eval('(' + data + ')').results;
$('#' + smartFillBoxId).show();
$.each(eval('(' + data + ')').results, function (index, results) {
htmlData = formatLocation(results,count);
$('#' + smartFillBoxId).append(
"<li><a href='#' onclick='addSelectedValue(\""
+ elementName + "\",\""
+ count + "\",\""
+ smartFillBoxId + "\")' >"
+ htmlData
+ "</a></li>");
count++;
});
});
}
Scenario:
1. Have a text box.
2. In the text box user will type minimum 3 characters.
3. Ajax will be executed with those characters
4. A smartfill box will list with appended values (as list)
Works fine when i am typing slowly in the text box.
But the smartfill data will list two/three times when I am typing fast in the text box.
The ajax call function is binded to 'onkeyup' event.