0

I just want to check condition within beforeunload event like other guy ask.My Code is here=>

 $(window).bind('beforeunload', function (e) {       
            if (CheckCondition())
                return "Are you sure to go?";
        });

function CheckCondition()
        {
            $.ajax({
                url: '/Field/CheckBeforeChangeURL',
                type: "GET",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (r) {
                    //Bool value return from server side
                    return r;
                },
                async: true,
                processData: false,
                cache: false
            });
        }

It still go without asking.I already try this beforeunload ignore condition but still not working.

Community
  • 1
  • 1
lwin
  • 3,784
  • 6
  • 25
  • 46
  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Mike Scotty Dec 23 '16 at 09:20
  • `$.ajax ` is asynchrone. Actually, your function `CheckCondition` return undefined so your if statement is never true. – Fefux Dec 23 '16 at 09:20
  • Thanks mpf82 and @Fefux .Let me ask a question.So can i use this with global temp variable? – lwin Dec 23 '16 at 09:42

0 Answers0