mirror of
https://gitlab.com/buildfeed/BuildFeed.git
synced 2024-03-22 21:10:34 +08:00
Timeouts and aborts for BuildFeed Search
This commit is contained in:
parent
509de0dc50
commit
b35447fdf7
|
@ -1,15 +1,31 @@
|
|||
$(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) {
|
||||
var template = $.templates("#result-template");
|
||||
var content = $("<div class='list-group'></div>");
|
||||
|
||||
var item = template.render(data);
|
||||
content.append(item);
|
||||
if (typeof bfsTimeout != 'undefined')
|
||||
{
|
||||
clearTimeout(bfsTimeout);
|
||||
}
|
||||
|
||||
search.after(content);
|
||||
});
|
||||
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>");
|
||||
|
||||
var item = template.render(data);
|
||||
content.append(item);
|
||||
|
||||
search.after(content);
|
||||
});
|
||||
}, 200);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user