gpt4 book ai didi

javascript - Angular 2 - 在 url 中发送带有标签的值

转载 作者:行者123 更新时间:2023-11-30 11:40:44 26 4
gpt4 key购买 nike

在我的应用程序中,我有一个已注册产品的列表。

我正在尝试在 url 中发送产品名称。

但是产品名称带有 # 主题标签并且产品名称到达服务器时不完整:

前端

var product = "PLASTIC #1JQ-M 1CV T-PLAS"
return this._http.get(Config.URL_SITE + 'list/productLen?product='+product)...

后端

router.get('/productLen', function(req, res, next) {
var productName= req.query.product;
console.log(productName) //PLASTIC
...

如何让productName变量接收全名?“塑料#1JQ-M 1CV T-PLAS”

最佳答案

你应该使用 encodeURIComponent()将产品名称添加到 URL 之前的功能。

var product = "PLASTIC #1JQ-M 1CV T-PLAS"
return this._http.get(Config.URL_SITE + 'list/productLen?product=' + encodeURIComponent(product))...

哈希后的所有内容都被浏览器剥离了Why the hash part of the URL is not in the server side? .

有替代解决方案:How to get Url Hash (#) from server side , 但它们主要是如何在服务器上检索一般的散列。

关于javascript - Angular 2 - 在 url 中发送带有标签的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42777973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com