Reputation: 177
I have an e-shop with filters. When someone uses filters, url changes with AJAX.
What i did is using .ajaxComplete function to check ajax completions. Inside this function i have a variable called replacer where i make multiple replaces like this:
var replacer = window.location.href.replace("&page=","/").replace("&sort=","/").replace("&order=","/").replace("...","...");
etc and i use
history.pushState("","",replacer);
to change my url and its working like a charm. But its working when a user selects an option from filters. When someone tries to select another filter, another ajax request is done and the same is done but now the replacer variable replaces the new replaced url.
Any ideas of somehow have the original generated url and to this to make the replacements and the history.pushState?
Thank you in advance
Upvotes: 0
Views: 645
Reputation: 5344
You can save the original "window.location.href" to somewhere (such as localstorage or the window object). And get the url every time u need it.
Upvotes: 1