title: How to resolve duplicate parameters in URL
body: <p>I have an Ajax select input that changes the URL when changed, the page does not refresh. However when the select input is changed multiple times, repeated parameters stack in the URL: </p>
  
  <blockquote>
    <p>[domain]/find.php?cat=1#pricemin=10&amp;pricemax=500#pricemin=10&amp;pricemax=500</p>
  </blockquote>
  
  <p>How can I use javascript to encode it back to:</p>
  
  <blockquote>
    <p>[domain]/find.php?cat=1#pricemin=10&amp;pricemax=500</p>
  </blockquote>
  
  <p>so that there are no duplicate parameters?</p>
  
  <p>An example of my current jQuery is as below:</p>
  
  <pre><code>$('#filterform select').on('change', function(e){
          var dummy = $('#filterform').serialize(),
              loc = $('&lt;a&gt;', {href:window.location})[0];
  
          someajaxfunction();//do ajax function here
          if(history.pushState){
              history.pushState(null, null, loc +'#'+ dummy);
          }
      });
  </code></pre>
  
  <p>I have tried replacing <code>loc</code> with <code>loc.pathname</code> and the repeated parameters problem is solved. However my <code>?cat=1</code> form parameter is gone as well which is not desired. I wish to look at this problem with a URL search-and-modify jQuery/javascript method, for example:</p>
  
  <p>What we have is</p>
  
  <blockquote>
    <p>[domain]/find.php?cat=1&amp;subcats%5B%5D=1&amp;subcats%5B%5D=2</p>
  </blockquote>
  
  <p>What we want is</p>
  
  <blockquote>
    <p>[domain]/find.php?cat=1&amp;subcats=1+2</p>
  </blockquote>
  
  <p>Is it possible?</p>
  
  <p><strong>Note:</strong> 5 minutes after posting this question I realised that using <code>loc.pathname + loc.search</code> solves my problem, sorry for the long post. I am still curious about a URL search-and-modify jQuery/javascript method. Would appreciate if anyone can provide a starting point, thanks!</p>