I am using jQuery ajax
function to get database values code and subcode.Whenever I get the code and subcode I have to get the name stored in another table corresponding to code and subcode.
First function i am using is
function loadSecretaries()
{
var items = "";
$.getJSON("Tac_members_GetTacSecretaries.php", function(data) {
$.each(data, function(index, item) {
var name = getSecretariesName(item.ECODE, item.ECODE_S);
items += "<option value='" + item.ECODE + "'>" + item.ECODE_S + </option>";
});
$("#select_reviewer_secretary").html(items);
});
}
The second function is
function getSecretariesName(code, subcode)
{
var items = "";
$.ajax({
async: false,
url: '../PhpProject1/Tac_Members_GetReviewerNames.php',
dataType: 'json',
type: 'POST',
data: {"code": code, "subcode": subcode},
success: function(response) {
alert(response.ename) ;
var name =response.ename;
//here i want to return ename to first function
},
error: function(x, e) {
if (x.status === 0) {
alert('You are offline!!\n Please Check Your Network.');
} else if (x.status === 404) {
alert('Requested URL not found.');
} else if (x.status === 500) {
alert('Internel Server Error - Please try after relogin to the application');
} else if (e === 'parsererror') {
alert('Parsing JSON Request failed.');
} else if (e === 'timeout') {
alert('Request Time out.');
} else {
alert('Unknow Error.\n' + x.responseText);
}
}
});
return name;
}
I am getting undefined
when alert 'name' in first function. How to solve this. Thanks in advance.