找不到JQuery encodeURIComponent页面错误

问题描述 投票:0回答:2

我正在尝试使用uri函数对我的encodeURIComponent进行编码。这是我的代码。

//res[0].CLIENT_ID=10 and id=res[0].CLIENT_ID
var url = "new_quotation.php?clientid="+res[0].CLIENT_ID+"&quoteid="+id;
var encodedurl = encodeURIComponent(url);
$('#edit').attr("href", encodedurl);

它成功编码了uri,但当页面重定向时,它显示错误为

在此服务器上找不到请求的URL /Quotation/new_quotation.php?clientid=10&quoteid=0000000014。

我看到了url。这好像是

http://localhost/Quotation/new_quotation.php%3Fclientid%3D10%26quoteid%3D0000000014

那么,uri是编码的,但为什么页面不被重定向?我是否需要使用任何其他功能进行重定向?或者我的代码中有错误吗?

javascript php jquery url encoding
2个回答
0
投票

您应该只编码值,而不是整个网址。

var url = "new_quotation.php?clientid="+encodeURIComponent(res[0].CLIENT_ID)+"&quoteid="+encodeURIComponent(id);
$('#edit').attr("href", url);

由于您使用的是jQuery,因此您也可以使用param()


0
投票

必须应用URL中的每个参数encodeURIComponent(如果参数由特殊字符组成)

示例:

var enc =param1+'/'+encodeURIComponent(param2)+'/'+encodeURIComponent(param3);

param2,param3 - 这里应该有特殊的字符

© www.soinside.com 2019 - 2024. All rights reserved.