I am working on a project which is developed by some other user and trust me the code is giving me really hard time to understand. The requirement that user wants is that there are some filters on the product page which is working fine now the user wants is that when the user selects some filters the url looks something like this
Now after this when user search from the main search bar for any content he wants to get results from whole products means. The current url after searching from main search bar looks something like this.
https://www.example.com/Year+3/General+Knowledge?term=History&sortby=relevance
I want to remove all the filters from url when user search from the main search bar means that my url should look like this after searching from main search bar.
As mentioned before the previous developer who wrote the code is giving me hard time to understand his logics so I thought of doing it through Jquery but that thing is also not working for me here is the jQuery code I am using write now.
<script>
$(document).ready(function(){
$('#term-submit').click(function(){
var term = $('#search-input').val();
var getUrl = window.location;
var baseUrl = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
console.log(baseUrl);
window.location.href = baseUrl + '?term=' + term + '&sortby=relevance';
});
});
Oh by the way the application I am working on is in Zend framework. Any help would be great. Thank you in advance.
Just solved it on my own it was the issue with my concetration :P I haven't noticed to add preventDefault() to clear up things so by adding it solves the issue. Now, my jquery looks like this.
<script>
$(document).ready(function(){
$('#term-submit').click(function(e){
e.preventDefault();
var term = $('#search-input').val();
var getUrl = window.location;
var baseUrl = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
window.location.href = baseUrl + '?term=' + term + '&sortby=relevance';
});
});
Hope it will help someone in the future.