Add parameter in javascript url

Asked

Viewed 523 times

0

My problem:

I have a property listing to be sorted every time a filter is made, the way I am doing when selected the sort option, the whole content is ordered and not the current one. How do I keep the url in the address bar without losing the current parameters and add the parameter(&sort=xxx)?

inserir a descrição da imagem aqui

JS CODE FOR ORDER

$("select.ordenacao").change(function() {
        $("select.ordenacao").each(function() {
          str = $( this ).val();
          //alert(str);
            //$("#ordenar").submit();
             location.href='lista?ctgr='+getValueQS("ctgr")+'&city='+getValueQS("city")+'&s='+getValueQS("s")+'&d='+getValueQS("d")+'&v=0'+'&vmin='+getValueQS("vmin")+'&vmax='+getValueQS("vmax")+'&submit='+getValueQS("submit")+'&ordenacao='+str;
        });
    });
function getValueQS(key) {  
      return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));  
    } 

I do not know if I am doing it correctly, because some parameters of the above function are passed the value, others are empty breaking my sql query.

  • Could you please post the final result? what comes out on Location.href?

  • The end result would be: http://localhost:8080/site-reform/list? ctgr=&city=&s=0&d=0&v=0&vmin=0&Vmax=9999999999&Submit=&sort=vmaior

  • @Igorsilva Ora, because you just don’t get the current full URL and concatenate with the new parameters?

  • I tried this: var url = $(Location). attr('href'); Location.href=url+'&oredenacao='+str; The problem is that if the user sorts without doing a filter before it will bug because the url will look like this: localhost:8080/site-reform/&sort=xxxx, would it look like this: localhost:8080/site-reform/list? ordination=xxx

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.