The script should take the user's session via ajax and transfer it to other ajax requests that take the data for the charts. The first request succeeds, but others have not, becouse sessionId for them is undefined. Tried to wrap them in a function, but unfortunately nothing happened. What can be done?
var sessionId,
requestInWorkCount,
requestInWorkPower;
function getSession(){
$.getJSON("http://192.168.1.142/DashboardService.svc/web/jsonLoginUser?UserID=User1&UserPassword=123", {},
function(data) {
$.each(data, function (key, val) {
sessionId = val.toString();
return sessionId;
})
});
};
function getData(session){
$.getJSON("http://192.168.1.142/DashboardService.svc/web/jsonGetIndicator?SessionID="+session+"&IndNum=1", {},
function(data) {
$.each(data, function (key, val) {
requestInWorkCount = val;
return requestInWorkCount;
})
});
$.getJSON("http://192.168.1.142/DashboardService.svc/web/jsonGetIndicator?SessionID="+session+"&IndNum=2", {},
function(data) {
$.each(data, function (key, val) {
requestInWorkCount = val;
return requestInWorkPower;
})
});
};
$(document).ready(function(){
getSession();
getData(sessionId);
setInterval('show()',1000);
});