0

I am using .net 1.1 and am trying to call a server side method using Jquery when clicking the browser close button.

<body  onbeforeunload="javascript:return test()" >
  TESTING  
</body>

function test()
{    
   debugger;   
   $.ajax({    
     type: "GET",    
     url: "HiddenPage.aspx/GetServerTime",   
     data: "{}",    
     contentType: "application/json; charset=utf-8",    
     dataType: "json",    
     success: function(msg) 
     {        
       alert(msg.d);     
     },    
     error: function(msg) 
     {       
       alert("Error! Try again...");     
     }          
     return false;          
   })

In code behind:

[WebMethod()]
public static DateTime GetServerTime()
{
     return DateTime.Now;
}

}

The problem is that the control doesnt go to the webmethod.

Ral Zarek
  • 1,058
  • 4
  • 18
  • 25
F11
  • 3,703
  • 12
  • 49
  • 83

2 Answers2

0

Try changing the type to POST.

Tapas Mahata
  • 343
  • 6
  • 22
-1

Try to see what the answer is with the program Fiddler.

Andreas
  • 64
  • 2
  • i m checking in IE developer tools,msg.d is showing undefined,msg.statusText is ok – F11 Dec 06 '12 at 12:58
  • What does the html response give? – Andreas Dec 06 '12 at 20:14
  • It is returning the whole page back,but control doesnt go to C# method – F11 Dec 07 '12 at 05:02
  • Then it probably is on the server side, check this out if it could help you. http://stackoverflow.com/questions/583116/call-asp-net-pagemethod-webmethod-with-jquery-returns-whole-page – Andreas Dec 07 '12 at 12:25