views:

2322

answers:

2

Hi,

I am trying to send an ajax request in the onunload event of a page. I am using the $.post function of jquery, but when the event actually fires i get this error: "Microsoft JScript runtime error: '$' is undefined"

Does this mean that the jquery library has been deferenced before the $.post function was called and so i will not longer be able to use Jquery?

What should be my approach to solve this problem? I am doing this in an Asp.net 2.0 web application project. Following is the JS script on the page.

<script type="text/javascript">


function RemoveFromOnlineUsers()
{
   debugger;
   if ($.browser.msie) 
   {
        alert("this is msie!");
   }

   $.post("../Main/FloatingWindowAjax.aspx", {REMOVEONLINEUSER : "<%=Master.UserId.ToString() %>" });       

    return false;
}
        window.onunload = RemoveFromOnlineUsers;


    </script>
A: 

Try this.. http://docs.jquery.com/Events/unload

gk
A: 

Sorry ppl, my silly mistake. I just found out that the jquery references in the master page failed to load on the page i was having the unload event, so after correctly resolving the jquery references using Page.ResolveUrl, the jquery in the unload event now works like an charm!

renegadeMind