Refresh exact URL by JavaScript or jQuery

Viewed 94

I am looking for a way to refresh the exact URL after ajax success. I try the following way:

location.reload()
history.go(0)
location.href = location.href
location.href = location.pathname
location.replace(location.pathname)

But in fact, I have another problem, the URL is https://example.com/electronic/?product_cat=mobile but after using the mentioned code, the URL will change and the URL will be https://example.com/electronic/

is there any way to keep ?product_cat=mobile after refreshing?

1 Answers

The easiest way of doing this will be

  1. Get the current URL.
  2. Redirect to it.
<script>
var current_url = window.location.href;
window.location.href = current_url;
</script>
Related