Asp.net MVC with Ajax history (jquery address), how to load

I am using asp.net mvc with ajax navigation. I use jquery address and I can change the address bar to be like “MYPage.Com/#/Url”, but how can I invoke my route when the user enters that link?This has probably been asked before but I could not find it, so please point me to it if …

via C Programming Language Tutorial » Search Results » ajax:

Asp.net MVC with Ajax history (jquery address), how to load

I am using asp.net mvc with ajax navigation. I use jquery address and I can change the address bar to be like “MYPage.Com/#/Url”, but how can I invoke my route when the user enters that link?
This has probably been asked before but I could not find it, so please point me to it if you find it.
……………………………………..

You need to use the window.onHashChange event of the window element. It is best to use javascript libraries like jquery bbq to handle the hash change.
If you still want to do it without using a library, then on page load you should make a call to the function that handles the onHashChange even.
……………………………………..

There is no event for that (at least not the last time I’ve checked). You need to make a checker function in JS that will run once every 100ms for example (or more often).
var currentHash=””;
function CheckHash()

if(currentHash!=window.location.hash)

currentHash=window.location.hash;
NavigateTo(currentHash); //or whatever code to execute when address behind `#` changes

}

CheckHash(); //Initial Run, for fast reaction on load
window.setInterval(CheckHash,100); //schedules the function to run once every 100ms

For more info: Asp.net MVC with Ajax history (jquery address), how to load

C Programming Language Tutorial » Search Results » ajax

Asp.net MVC with Ajax history (jquery address), how to load

Share this post:

Related Posts

Leave a Comment