0

I am working on a method to check for an invalid session variable in my asp.net project. Its a known fact that session variables tend to invalidate un-predictably in big projects.

Though I tried almost everything but with no success. Now I am working on a different way to handle it. Please refer jQuery form submit. I have a modal popup in the end of the form and then I have added the $("form").submit() event of jQuery to check for invalid session state and then if state is invalid, invoke login modal, which again using XHR sends the user login credentials to the server to recreate the session.(Please note that I am a little new to jQuery)

Here is my code:

 $(document).ready(function () {
    $("form").submit(formSubmit);
    function formSubmit() {
        $.get("CheckForSessionTimeOut.aspx", function (data) {

            if (data == "0") // Session is null
            {
                getModal();//Method to invoke the popup 
                return false;
            }
            else if (data == "1") // Session is valid or not null
            {
                //submit the form
            }
        });
    }
});

But the problem here is the form posts back without the modal with some javascript error. and in case if I use e.preventDefault(); to prevent from default postback in submit(); method the form does not posts back at all.

4

1 回答 1

0

也许题外话,但我认为你应该在任何情况下提交表单,如果会话无效,返回错误。如果您需要重新创建会话,您可以将用户重定向到登录页面。

于 2013-10-06T19:31:57.733 回答