I need to send request on events keyUp/keyDown etc. I Implemented ajax calls and the first call works good but its extremely slow and more often freezes the input field. I would like to go with the second call but the problem is, i cannot access an array object that is populated after success. Although the array object has response on it, the length is always 0. [Image of console.log][1] I would appreciate if i could get help with it. Thank you in advance.
//First Call
apiCallBind: function(){
var ajaxReturn = $.ajax({
url: "example.php",
data: {currentQuery: "test"},
async: false,
global: false
}).responseText; }
return ajaxReturn.items;
}
//Second Call
apiCallBind: function () {
var url ="example.php";
var test = [];
$.ajax({
url: url,
data: {currentQuery: this.query()},
success: function (response) {
test.push(response);
}
});
console.log("Test Length::" + test.length);
console.log(typeof test);
console.log(test);
}
[1]: https://i.stack.imgur.com/E607A.png