Skip to content

Instantly share code, notes, and snippets.

@rubensayshi
Created October 24, 2012 09:24
Show Gist options
  • Save rubensayshi/3945063 to your computer and use it in GitHub Desktop.
Save rubensayshi/3945063 to your computer and use it in GitHub Desktop.
function setupAjaxSearch() {
var req = null;
var $resultdiv = $('div.results');
var $searchbox = $('input.search');
function doSearch(value) {
if (req != null) req.abort();
req = $.ajax({
type: "GET",
url: "/search.php",
data: {'search' : value},
dataType: "html",
success: function(html){
$(resultdiv).html(html);
}
});
}
$searchbox.on('change', function(e) {
doSearch($(this).val());
e.preventDefault();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment