I have an Ajax call inside a function like so:
function send_data(url, data) {
$.ajax({
url: url,
type: 'POST',
data: data,
success: function (data) {
//Empty for now
},
error: function (xhr) {
return xhr.responseJSON;
},
});
}
and then I trigger this function like so:
console.log(send_data(url, data));
I should receive the response output, but I don't. I instead, get undefined. I know JavaScript is asynchronous, but shouldn't this work? I added a console.log
output inside the error function, before the return statement, and it outputs the data correctly. So why doesn't it return the data?