A puzzle with hashchange and navigation

A puzzle with hashchange and navigation


In general, hash changes are created whenever a link is clicked in jQuery mobile. When a link is clicked, jQuery mobile will make sure that the link is referencing a local URL, and if so, it'll prevent the link's default click behavior from occurring and request the referenced url via Ajax instead. When the page returns successfully, it will set the location.hash  to the new page's relative url.




Hash changes that occur independently of a click, such as when a user clicks the back button, are handled through thehashchange event, which is bound to the window object using Ben Alman's hashchange special event plugin (included in jQuery Mobile). When a hash change occurs (and also when the first page loads), the hashchange event handler will send the location.hash to the $.mobile.changePage() function, which in turn either loads or reveals the referenced page.


According to the two paragraphs above from jquery mobile 's docs, I got two conclusions :
  1. link click -> ajax request(successful) -> update location.hash
    (from the first paragraph)



  2. link click -> update location.hash -> hashchange event(trigger) -> changePage(called by hashchange event handler)
    (from the second paragraph)

so,I think the two conclusions are conflicting .

I regard the transition process as three parts ( click , hashchange and navigation  ). Does hashchange cause navigation or navigation cause hashchange? who can tell me.

Perhaps this question is very strange.
And my english is very poor.....
Thanks.