I have the following code:
$("#search").keyup(function(){
if($("#search").val().length > 2){
var returnedValue = (notes.search($("#search").val()));
console.log(returnedValue);
}
});
notes = (function(){
return{
search : function(data){
var result = "";
$.ajax({
type:"GET",
url:"/search",
dataType:"text",
timeout:2000,
data:{noteTitle:data},
success:function(data){
if(data == 'false'){
console.log('no data');
}else{
result = JSON.parse(data);
return(result);
}
},
error:function(xhr,type){
console.log("ajax error");
}
});
},
})();
Returned value is always undefined. It's obviously a scoping issue, but I can't seem to figure out how to return the data from the ajax request to anything outside the module.