I have an input box on which there is an ajax request on every key press. so if i enter word "name" there will be 4 successful request. So i actually want only the latest request of executed. so if i enter word "name" there will be only one request which will be the last one.
and i also have a solution for this (this is a simple example with click method)
JS script
var callid = 1;
function ajaxCall (checkval ){
    if(checkval == callid){
        $.ajax({
            type: 'post',
            url: baseurl + "test/call_ajax",
            data: {
                val: "1"
            },
            success: function(data) {
                console.log(data)
            }
        });
    }
}
function call(){
    var send = callid+=1;
    setTimeout( function(){ ajaxCall(send)  } , 500);
}
html script
<a href="#" onclick="call()" > Call ajax </a>
This is working perfectly. But i was think if there is way to refine it a little bit more.
Any ideas :)
 
     
     
    