Load page once jQuery ajax call is executed.

Dinesh Bali
Dinesh Bali used Ask the Experts™
on
HI,

I am working on .Net application using C#
I JQuery, I wanted that page should not render until my ajax function is not executed.
Please advise the solution
Code below:
$( window ).load(function() {
        
		$.ajax({
        url: '/der/surface/userHasSession',
        data: { currURL: window.location.pathname + window.location.search },
        type: 'GET',
        xhrFields: { withCredentials: true },
        accept: 'application/json',
        async: false
    }).done(function (userdata) {
       
			console.log('Done');


    })
        
        .fail(function (jqXHR, textStatus, error) {
            console.log('Session Check Fail: ');
        })
}
		
});

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Multitechnician
Top Expert 2014
Commented:
</head>
<body><!-- <===== PLEASE NOTE THIS IS YOUR BODY TAG -->
<script>
    $.ajax({
        url: '/der/surface/userHasSession',
        data: { currURL: window.location.pathname + window.location.search },
        type: 'GET',
        xhrFields: { withCredentials: true },
        accept: 'application/json',
        async: false
    }).done(function (userdata) {
        console.log('Done');
    }).fail(function (jqXHR, textStatus, error) {
        console.log('Session Check Fail: ');
    });
</script>

Open in new window

Author

Commented:
Many thanks for your reply.

When I moved my script in body then I am getting error at below line. What is the reason?

$.cookie('VerifySSOLogin', '1');
Error is:
jquery-2.1.4.min.js:2 Uncaught TypeError: $.cookie is not a function
leakim971Multitechnician
Top Expert 2014

Commented:
you need to move the jQuery and cookie plugins inside this script block too

Author

Commented:
Really great.
It works fine.

Since it is taking time to load as too much processing on server for business rules.
Anyway we can put loader at the time of processing.

If you want I can raise another question for the resolution.

Please advise.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial