猿问

PHP encodeURIComponent 重置

<a href="{{ payment.approve}}" class="pointer"><i class="fa fa-ban color-red"></i> Approve Payment</a>

<a href="{{ payment.reject}}" class="pointer"><i class="fa fa-ban color-red"></i> Reject Payment</a>

<script>    

if (filterpayment) {

        url += '&filterpayment=' + encodeURIComponent(filterpayment);

    }

</script>

使用过滤器后”我的网址将是这样的


http://localhost/index.php?route=sales/filterpayment&user_token=XXXXXX&filterpayment=2&page=2


对于第 2 页是“分页”


我想要的是,在执行操作(例如单击批准)后,如何在不删除“page2”的情况下重置它


单击后我想要的是:批准


http://localhost/index.php?route=sales/filterpayment&user_token=XXXXXX&page=2


我试过的:


url = 'index.php?route=sales/filterpayment&user_token={{ user_token }}';

location = url;

但它会直接重置 URL 中的“page2”并变成这个


http://localhost/index.php?route=sales/filterpayment&user_token=XXXXXX


大话西游666
浏览 202回答 1
1回答

呼如林

使用搜索参数let url = new URL("http://localhost/index.php?route=sales/filterpayment&user_token=XXXXXX&page=2")let filterpayment = 2;if (filterpayment) {&nbsp; url.searchParams.set("filterpayment",encodeURIComponent(filterpayment));}console.log(url)filterpayment = 0;if (filterpayment) {&nbsp; url.searchParams.set("filterpayment",encodeURIComponent(filterpayment));}else {&nbsp; url.searchParams.delete("filterpayment");}console.log(url)
随时随地看视频慕课网APP
我要回答