i have script like this.
function getContactLastDateOfDeparture(contactId) {
$.get(
'/transaction/ajaxGetContactLastDateOfDeparture/'+contactId,
'',
function(data){
alert(data);
return data;
},
'json'
);
}
I test script above with console.log(getContactLastDateOfDeparture(2144)), when in alert phase it outputted string 2011-12-06, but when phase return it outputed undefined
How to make the return should be 2011-12-06 ?
You can’t really do a return in an AJAX function, as it is asynchronous. It is better to call another function at the end if you want to pass along the value.
To do this, you can pass it along like this: