Click here to Skip to main content
15,904,817 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I want to make a call to web service through jquery ajax on page navigation.
whenever i click on any other navigation link in page i want to make a service call.i tried using onbeforeunload event but it is not successful.


Thanks in advance.
Posted
Comments
How do you navigate?
[no name] 19-Jan-16 12:49pm    
After calling web service you want bind data or any different logic. Secondly do you want to call through javascript or server side code.

1 solution

I think better to handle this event on navigation link click.
That is handle event click on navigation link click and call the ajax method and then navigate to required url.

Required code will be like below

JavaScript
   $("a").click( // If you want to handle for specific link then use particular id
    function(event){
    
       event.preventDefault();
       //Do ajax call here
    } 
    );
}



Hope this will works. Good luck :)
 
Share this answer
 
Comments
F-ES Sitecore 19-Jan-16 10:34am    
That will stop the click working, you'll want to omit the preventDefault and just call the web method in the click event.
Richard Deeming 19-Jan-16 11:15am    
Which then might fail, depending on whether the browser stops all scripts running on the current page when navigating away from it. :)
F-ES Sitecore 19-Jan-16 11:17am    
Which is why doing these kinds of things are fairly pointless, especially if the call is important. Google analytics uses this method but obviously it's not a vital part of your site.
[no name] 20-Jan-16 3:56am    
when i navigate to other page if the previous page has any temp files uploaded before loading the new page i want to clear the files uploaded from temp directory.for that i want call a web service method..
Sri Nivas (Vasu) 20-Jan-16 4:31am    
then we don't need event.preventDefault();. You can call ajax method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900