Why is timeperiod null
const url = 'http://example.com?timeperiod=lasttwentyeightdays&pagesize=20'
const args = new URLSearchParams(url);
alert('timeperiod='+args.get('timeperiod') + ' and pagesize='+ args.get('pagesize'));
But in the below code it works
const url = 'http://example.com?x=c&timeperiod=lasttwentyeightdays&pagesize=20'
const args = new URLSearchParams(url);
alert('timeperiod='+args.get('timeperiod') + ' and pagesize='+ args.get('pagesize'));
You need to create a URL object and then retrieve the params with url.search
:
See
const url = new URL('http://example.com?timeperiod=lasttwentyeightdays&pagesize=20');
const args = new URLSearchParams(url.search);
console.log(`timeperiod=${args.get('timeperiod')} and pagesize=${ args.get('pagesize')}`);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With