Return from jQuery Ajax Method
- by Lijo
I have a button named searchReportButton. On this button click, I need to check session value from server using a ajax web method "Error.aspx/CheckSessionExpiry".This is done in checkSession javascript function. The checkSession is not returning anything now - instead it is handling the required operation based on the result (redirecting to error page).
I need to return the result of ajax web method to the Main Caller. How can we do this return?
Main Caller
searchReportButton.click(function () {
checkSession();
//Remainging Code
});
Helper
function checkSession() {
var win = 101;
$.ajax(
{
type: "POST",
url: "Error.aspx/CheckSessionExpiry",
data: '{"winNumber": "' + win + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: handleSessionResult
}
);
}
Result Helper
function handleSessionResult(result) {
if (result.hasOwnProperty("d"))
{
result = result.d
}
if (result == "ACTIVE")
{
window.location.href("Error.aspx");
return false;
}
//alert(result);
}