I have a scenario where I am making an AJAX call in one function and attempting to capture the result in another function. Let me explain this in detail below:
function myMain(){
var test = myWPackage();
alert(test);
}
function myWPackage(){
var tender_number = "TENDER_TEST-123";
// Making an AJAX call
$.ajax
({
url: "getWorkPackage.php",
type: "POST",
dataType: 'json',
data: {source1 : tender_number},
cache: false,
success: function (work_package)
{
return work_package[0];
})// End of AJAX call
}
The database is connected, and the value is retrieved if I replace 'return' with 'alert' in myWPackage function. Therefore, the issue does not lie with the database or the data being fetched.
However, when I call the myMain() function, it returns "UNDEFINED". Can someone point out what mistake I am making? I am trying to retrieve the value from the AJAX call and store it in 'test' variable.
Thank you in advance.