storing value after Ajax function calling

Feb 28 2019 6:33 AM
Hy guys i stuck in storing value to a variable after calling ajax method , i am not able to use 
callback in ajax....
 
Someone help me please...
 
 
here is the code===============
 
var s = GetSessionValue("userId");
alert(s);
 
 
function GetSessionValue(key1) {
$.ajax({
type: "POST",
url: "Service1.asmx/GetSessionValue",
data: '{key: "' + key1 + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
function OnSuccess(result) {
return result.d;
alert(result.d);
}
}
 ===============================
 
AJAX methods are calling sucessfully , data also getting correct...
 
 
but i want to return the value from ajax function and want to store in another variable .
 
 In my existing code 
var s = GetSessionValue("userId");
alert(s);
 
Im getting undefind value.
 
I know some callbak logic is required , but im not able to implement in this case ....
 
 i need someone help ...
 
Thanks  
 

Answers (5)