Skip to content

Instantly share code, notes, and snippets.

@jsangilve
Last active December 16, 2015 07:49
Show Gist options
  • Save jsangilve/5401611 to your computer and use it in GitHub Desktop.
Save jsangilve/5401611 to your computer and use it in GitHub Desktop.
Simple jQuery snippet for input with XMLHTTPRequest (Ajax)
$(function () {
var timer;
$('#id_input').keyup(function() {
clearTimeout(timer);
var val = this.value
var ms = 1000
timer = setTimeout(function() {
getSomething(val)
}, ms)
});
})
function getSomething(param) {
var url = 'http://mysite.com/getsomething'
$.get(url, {parameter: param}, function(data) {
doSomething(data)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment