I have used the below code to get a value, but it is not working. The post method returns the correct value, but I want to assign the value to a variable, but it is not working. How can I fix?
$(document).ready(function () {
var sessionID = GetSessionIDFromDB();
alert(sessionID);
});
function GetSessionIDFromDB() {
$.ajax({
type: "POST",
url: myurl + "GetSessionID",
data: '{}',
contentType: "application/json",
dataType: "json",
success: function (data) {
var returnValue = $.parseJSON(data.d);
return returnValue;
}
});
}
The returnValue
in GetSessionIDFromDB is what I expect, but when assigned to a variable, it is null.