Skip to content

Instantly share code, notes, and snippets.

@flanger001
Created July 8, 2014 20:39
Show Gist options
  • Save flanger001/98539eba9799ee4bb788 to your computer and use it in GitHub Desktop.
Save flanger001/98539eba9799ee4bb788 to your computer and use it in GitHub Desktop.
A simple implementation of a delayed search with jQuery and Ajax
var ReverseSearch = {
onReady: function(){
$("#rsearch input").on("keyup change", ReverseSearch.wait);
},
wait: function(e){
clearTimeout($.data(this, 'timer'));
if (e.keyCode == 13){
ReverseSearch.rsearch(true);
} else {
$(this).data('timer', setTimeout(ReverseSearch.rsearch, 500));
}
},
rsearch: function(){
var raddress = $("#rsearch input[name='address']").val(),
rstate = $("#rsearch input[name='state']").val();
$.post("ajaxScripts/if-address-reverse-search-ajax.php", { address: raddress, state: rstate })
.done(function(data){
var results = $("<div/>", {
html: data
});
$("#rsearch-results").html(results);
});
}
};
$(document).ready(ReverseSearch.onReady);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment