Created
July 8, 2014 20:39
-
-
Save flanger001/98539eba9799ee4bb788 to your computer and use it in GitHub Desktop.
A simple implementation of a delayed search with jQuery and Ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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