如果用户在搜索面板上输入了查询参数,我需要更新URL。我正在尝试以下方法:
$( document ).ready(function() {
if ($('.o_website_license_search_panel').length) {
$('.o_website_license_search_panel .o_search_submit').click(function () {
var search = $.deparam(window.location.search.substring(1));
console.log('before update')
console.log(window.location.search)
search.license_key = $(".o_website_license_search_panel input[name='license_key']").val();
console.log('new obj ', search, $.param(search))
window.location.search = $.param(search);
console.log('after update')
console.log(window.location.search)
});
}
});
我得到了以下输出:
before update
web.assets_frontend.js:1254 ?license_state=cancel
web.assets_frontend.js:1255 new obj {license_state: "cancel", license_key: "test2"} license_state=cancel&license_key=test2
web.assets_frontend.js:1256 after update
web.assets_frontend.js:1257 ?license_state=cancel
正如您所看到的,window.location.search
保持不变。我是否有所遗漏,还是这是设计上的意图?..
location.search
会自动重新加载页面,所以我一直在手动调用location.reload()
。移除这个调用后问题得到解决,现在它完美地工作了。 - F1Krazy