First, I know this is conceptually a duplicate question. I went through this one and I really didn't understand how/where to do the callback in my case.
In the code below what I want to do is return the Value of Agents
function CheckWebChatAvailability() {
var Agents = 0;
$.get(baseURL + url2, function(data, status) {
if (status == "success") {
$.post(baseURL + url, queuequery, function(data, status) {
Agents = parseInt(data.queue.agentsAvailable);
}); // end $.post for Server1
} // end if
else {
$.get(baseURL + url2S2, function(data, status) {
$.post(baseURL + urlS2, queuequery, function(data, status) {
Agents = parseInt(data.queue.agentsAvailable);
}); // end $.post for Server2
}); // end $.get for Server2
} // end else
}); // end $.get for Server1
} // end function CheckWebChatAvailability
ADDED:
I want to return the value of Agents
so that I can do something like show/hide a div
based on the result. I don't want to do that inside CheckWebChatAvailability
because it may be called from differents part of the code.
So I want to do, say, var myAgents = CheckWebChatAvailability();
or if that is not possible, var myAgents = newFunctionThatCallsCheckWebChatAvailability()