jQuery/Javascript - reload current page with an appended querystring?

后端 未结 6 491
小鲜肉
小鲜肉 2021-02-03 18:40

I\'ve got a dropdown menu on my form, which when something is selected I need to reload the current page, but with an appended querystring.

How would I go about doing th

6条回答
  •  无人共我
    2021-02-03 19:00

    This is an old question but it came up first in google search results.

    The solution I went with is similar to jAndy's.

    window.location.pathname gives me the page's url without the query string. I'm then able to build the query string with "?"+$.param({'foo':'bar','base':'ball'}) which I then append to the pathname and set to window.location.href.

    window.location.href = window.location.pathname+"?"+$.param({'foo':'bar','base':'ball'})
    

提交回复
热议问题