I have passed one more parameter 'callback' to the function as follows:
function getOrgList(empno, callback) {
var URL = "http://xxx.xx.xxx.xxx/ApprovalSystem/api/Organisation/getOrganisationChart";
$.support.cors = true;
$.mobile.loading('show', { text: "Getting Details..", textVisible: true, theme: "a" });
userData.EmpDetails = new Array();
userData.EmpDetails[0] = new Object({ EmpID: empno });
$.ajax({
url: URL,
type: 'POST',
data: JSON.stringify($.toJSON(userData)),
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.status == "true") {
buildChart(data);
$.mobile.loading('hide');
callback();
}
else {
$.mobile.loading('hide');
$('#divAlert').text(data.statusmessage);
$('#popupAlert').popup('open');
setTimeout(function () { $("#popupAlert").popup("close") }, 2000);
}
},
error: function (xhr, textStatus, err) {
$.mobile.loading('hide');
$('#divAlert').text("Request failed: " + err);
$('#popupAlert').popup('open');
setTimeout(function () { $("#popupAlert").popup("close") }, 2000);
}
});
}
And in the place where function to be called, I have written below code
getOrgList(empno, function () {
$.mobile.changePage("#divDetails", { transition: "slide", reloadPage: false, changeHash: true });
});
That's simple solution :)