I have an ajax method which submits data over ajax. The server then responds with a URL to load. Most times the URL will be different to the one on which the request was made, but sometimes the URL is the same.
Either way, I want the page to go to the intended url, even it's just reloading the page.
I've tried the window.location.href = '' method, but if the current url is the same as the intended url, nothing happens.
I've tried the window.location.replace(url) method, but that doesn't reload the page if current === intended.
I've tried the window.location.reload(true) method, but that's only good if the current url is the same as the intended url.
I've tried to compare the intended URL to the current url and do either a reload or a href method, but this has problems as well. If I click on a bootstrap tab, the hash doesn't appear in the URL, so the current url value is actually incorrect.
For your reference, this is/was my comparison:
if(window.location.href === response.intended) {
window.location.reload(true);
} else {
window.location.replace(response.intended);
}
All I want to do, is force the browser to redirect to an intended URL, or reload the current page depending on current URL vs intended URL.
#character in the url?#the page is just moving to the post. but if you remove that#, its reloading the whole page. Try and check the difference. This might be the issue I guess.window.location.href = someurl.com/test.php#tab_1doesn't reload / redirect the page.