I want to remove everything after searching with jQuery

Asked

Viewed 60 times

-2

Here is the url:

.../search? type=APARTMENT%2FAPTO+Duplex&area_de=&area_at=&valor_de=&valor_at=&bairro=Auxiliadora&bairros%5B%5D=Auxiliadora&code=&enviar=Buscar&Ord=&fespecial=&pagina=1&fespecial=novopronto&fespecial=novopronto

I would like to remove everything that comes after Buscar to perform a new query with jQuery.

$("#fe2").click(function(){

    var url         = window.location.href;
    ...
  • The problem with this is that if the order changes, how will you ensure that you have actually removed the required items?

  • In fact the order only changes once while not clicking the button again,then no influence but it was well rescheduled!!! :)

1 answer

2

Follow two solutions:

Using split, but you have to insert the Buscar again:

var url = window.location.href.split("Buscar")[0] + "Buscar";

Using regex:

var url = window.location.href.match(/.*Buscar/);

Browser other questions tagged

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