Skip to content

Instantly share code, notes, and snippets.

@ganmacs
Last active December 25, 2015 16:49
Show Gist options
  • Save ganmacs/7008664 to your computer and use it in GitHub Desktop.
Save ganmacs/7008664 to your computer and use it in GitHub Desktop.
var
preFunc = null,
preInput = '',
input = '',
ajaxPost = function(input) {
// apiコール
};
$('#ajax_form').on('keyup', function() {
input = $.trim($(this).val()); //前後の不要な空白を削除
if(preInput !== input){
clearTimeout(preFunc);
preFunc = setTimeout(ajaxPost(input), 500);
}
preInput = input;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment