我正在尝试使用uri
函数对我的encodeURIComponent
进行编码。这是我的代码。
//res[0].CLIENT_ID=10 and id=res[0].CLIENT_ID
var url = "new_quotation.php?clientid="+res[0].CLIENT_ID+""eid="+id;
var encodedurl = encodeURIComponent(url);
$('#edit').attr("href", encodedurl);
它成功编码了uri
,但当页面重定向时,它显示错误为
在此服务器上找不到请求的URL /Quotation/new_quotation.php?clientid=10"eid=0000000014。
我看到了url
。这好像是
http://localhost/Quotation/new_quotation.php%3Fclientid%3D10%26quoteid%3D0000000014
那么,uri是编码的,但为什么页面不被重定向?我是否需要使用任何其他功能进行重定向?或者我的代码中有错误吗?
您应该只编码值,而不是整个网址。
var url = "new_quotation.php?clientid="+encodeURIComponent(res[0].CLIENT_ID)+""eid="+encodeURIComponent(id);
$('#edit').attr("href", url);
由于您使用的是jQuery,因此您也可以使用param()
必须应用URL中的每个参数encodeURIComponent(如果参数由特殊字符组成)
示例:
var enc =param1+'/'+encodeURIComponent(param2)+'/'+encodeURIComponent(param3);
param2,param3 - 这里应该有特殊的字符