I realize this is asked a lot and usually the answer is that AJAX is asynchronous and this is why it's returning undefined, but even though I set my async to false here, it's still returning undefined when the function is called. res is always undefined
function sendRequest(link, type, query) {
$(document).ready(function(){
$.ajax({
'url' : link,
'type' : type,
'data' : query,
'async' : false,
'dataType': "json",
'headers': {
'Cache-Control':'max-age=0',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Content-Type':'application/x-www-form-urlencoded',
'Accept-Language':'en-US,en;q=0.8,ar;q=0.6',
},
'success': function(data) {
var res = data;
}
});
});
return res;
}
Also I am sure that the request is being sent correctly and that the response is received correctly as well