我有一个数据库,可以选择过滤。对于JSON,我希望过滤可以与JavaScript一起使用。
我现在遇到的问题是,这是我过滤时的网址示例:
index.php?action=page=activities&dayparts%5B%5D=2
我希望它是:
index.php?action=&page=activities&dayparts%5B%5D=2
这是我使用的代码:
const getActivities = async () => {
const $form = document.getElementById('form--filter');
console.log($form);
const data = new FormData($form);
const entries = [...data.entries()];
console.log('entries:', entries);
const qs = new URLSearchParams(entries).toString();
console.log('querystring', qs);
const url = `${$form.getAttribute('action')}?${qs}`;
console.log('url', url);
const response = await fetch(url, {
headers: new Headers({
Accept: 'application/json'
})
});
const activities = await response.json();
updateList(activities);
console.log(activities);
window.history.pushState({},
'',
`${window.location.href.split('?')[0]}?action=${qs}`
);
}
是否可以将&添加到网址中?