我试图使用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被编码了,但是为什么不重定向页面呢?我是否需要使用任何其他函数来重定向?或者我的代码中有错误吗?
发布于 2013-12-20 21:03:21
应该只对值进行编码,而不是对整个url进行编码。
var url = "new_quotation.php?clientid="+encodeURIComponent(res[0].CLIENT_ID)+""eid="+encodeURIComponent(id);
$('#edit').attr("href", url);
由于您使用的是jQuery,所以也可以使用param()
。
发布于 2018-11-05 09:10:40
URL中的每个参数都必须应用encodeURIComponent (如果该参数由特殊字符组成)
例子:
var enc =param1+'/'+encodeURIComponent(param2)+'/'+encodeURIComponent(param3);
param2,param3 --这里有一些特殊的字符
https://stackoverflow.com/questions/20715632
复制相似问题