Return from jQuery Ajax Method
Posted
by
Lijo
on Stack Overflow
See other posts from Stack Overflow
or by Lijo
Published on 2012-12-02T10:39:00Z
Indexed on
2012/12/02
11:04 UTC
Read the original article
Hit count: 120
jQuery
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);
}
© Stack Overflow or respective owner