Shruti
Shruti

Reputation: 149

query string apending after url in jquery

i have a anchor like:

<div class="fc-content cursor event_border' onclick="test(edate)"></div>

calling function is given below:

<script type="text/javascript">
   function test(id,evntDate)
   {
      var str = evntDate.toString();
      str = str.replace(/\//g,'');
      var pathname = window.location.pathname; // Returns path only
      var url      = window.location.href; 
      var querystring ='?date='+str;
      window.location.replace(url+querystring);

   }
</script>

after this i am getting the url like:

localhost/abc/cde?date=2018-07-26

but when i click again on this url its returning me the query string like:

http://localhost/proflyt/dashboard?date=2018-07-26?date=2018-07-24

its not removing the first query string and returning me the url like so because of this i am not able to use my code further can anyone please help me related this ?? i am new in jquery i am stuck here not able to solve and not getting any kind of response please help me related this ..

Upvotes: 0

Views: 36

Answers (1)

Mr.Js
Mr.Js

Reputation: 96

You need just use origin and pathname instead href.

<script type="text/javascript">
   function test(id,evntDate)
   {
      var str = evntDate.toString();
      str = str.replace(/\//g,'');
      var pathname = window.location.pathname;
      var ogigin      = window.location.ogigin; 
      var querystring ='?date='+str;
      var url = ogigin + pathname + querystring
      window.location.replace(url);

   }
</script>

Upvotes: 1

Related Questions