javascript - jQuery/Javascript - 使用附加的查询字符串重新加载当前页面?

标签 javascript jquery

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.

我该怎么做?

最佳答案

这是一个老问题,但它在谷歌搜索结果中排在第一位。

我采用的解决方案与 jAndy 的类似。

window.location.pathname 给我没有查询字符串的页面 url。 然后,我可以使用 "?"+$.param({'foo':'bar','base':'ball'}) 构建查询字符串,然后将其附加到路径名并设置为 window.location.href

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

关于javascript - jQuery/Javascript - 使用附加的查询字符串重新加载当前页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3281020/

相关文章:

javascript - Angular 5 使用标签到页面 anchor 的路由

javascript - 如何在单击按钮时获取和输出里程表的当前值?

javascript - jquery Cropper getData 函数返回一个对象而不是数据 :image

jquery - ASP.NET MVC - 页面卸载

javascript - HTML/JQuery : Button Only Working Once

javascript - 清除模型并重置为默认值时防止模型设置 `change` 事件?

javascript - 数组的内存分配

javascript - 如何更新附加 div 的数量计数

javascript - 这个CSS is not a function错误如何解决

javascript - 将 html 放入 iframe(使用 javascript)