Here is my code:
function ajaxRequest(value, path, website){
window[website] = $.ajax({
url : path,
type : 'GET',
data: { "name": value,
"_token": $('meta[name="_token"]').attr('content')
},
beforeSend: function(){
if(window[website] != null) {
window[website].abort();
}
},
success: function (people) {
return [status, people];
},
error: function (jqXHR, textStatus, errorThrown) {
return [status, textStatus];
},
timeout: 15000
});
}
As you see, it's a function that sends ajax requests. I call it like this:
var res = ajaxRequest('Jack', 'search/twitter', 'twitter');
console.log(res);
It returns:
Why I don't see the result in the console? Noted that I can see the result in the console if I send that ajax out of function. (the result is an array of data)
How can I fix the problem?