Example:
I starting typing "b". Then it would fire off an ajax call to get all the data with the letter "b".
Next I typed "a". So my search input box looked like this "ba". And firing off another ajax call to get all the data with the letters "ba".
I didn't know this but you can put the ajax request in a variable and kill it. Check it out.
<script type="text/javascript">
var ajaxCall;
typeAheadSearch = function(){
if(ajaxCall != undefined){
ajaxCall.abort();
}
ajaxCall = jQuery.ajax({
url: "http://www.somedomain.com/typeAheadSearch/_results.cfm",
data:{search:jQuery("##search").val()},
success:function(data){
jQuery("##results").html(data);
}
});
};
</script>
I started a variable called "ajaxCall" to store the request in. The first thing I do in the typeAheadSearch() is kill the current request by calling abort(). The next thing that I didn't know you could is that jQuery's ajax() returns the request. This is so handy.