Even though this question has already been answered and I have been through some of them, I still can't find what am I doing wrong.
Basically I have a function which return the success result of ajax:
var Functioncalling = function(id){
var Infotoreturn=null;
formdata = {
'id': id
};
$.ajax({
type: 'POST',
url: 'http://localhost:20012/pr/servlet',
data: formdata,
contentType: "text/html",
success: function(result){
console.log("1="+result);
Infotoreturn = result;
}
});
console.log("2="+Infotoreturn);
return Infotoreturn;
}
Calling the function:
var idreturned = Functioncalling(idvalue);
console.log("3="+idreturned);
Now in my first console output I'm getting exactly the data as I'm suppose to. But the second and third output both is null.