Ajax在popstate事件上

I am trying to handle the popstate event.The problem is that in the same page i use links like:

  1. localhost/item/category
  2. localhost/item/category/subcategory

So i have 2 ajax functions to load contents for each of above examples.When i press the back button of browser, i go back with 2 different ways:

  • localhost/item/category/subcategory2 , to --> localhost/item/category/subcategory1

or

  • localhost/item/category/subcategory to--> localhost/item/category

How can i check every time the url and according to this, call one of my 2 ajax functions to load the correct content?

You could use the window.location object to retrieve the current URL https://developer.mozilla.org/fr/docs/Web/API/window/location