Timeouts and aborts for BuildFeed Search

This commit is contained in:
Thomas Hounsell 2014-12-03 11:52:03 +00:00
parent 509de0dc50
commit b35447fdf7

View File

@ -1,8 +1,23 @@
$(function () {
var bfsAjax;
var bfsTimeout;
$(function () {
$("#search-input").keyup(function () {
var search = $(this);
$(this).parent().find(".list-group").remove();
$.ajax("/api/GetSearchResult/?query=" + $(this).val()).done(function (data) {
if (typeof bfsTimeout != 'undefined')
{
clearTimeout(bfsTimeout);
}
if (typeof bfsAjax != 'undefined' && bfsAjax.readyState != 4)
{
bfsAjax.abort();
}
bfsTimeout = setTimeout(function (object) {
bfsAjax = $.ajax("/api/GetSearchResult/?query=" + $("#search-input").val()).done(function (data) {
var template = $.templates("#result-template");
var content = $("<div class='list-group'></div>");
@ -11,5 +26,6 @@
search.after(content);
});
}, 200);
});
});