[英]JQuery encodeURIComponent page not found error
我正在嘗試通過使用encodeURIComponent
函數對uri
進行編碼。 這是我的代碼。
//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已編碼,但為什么不重定向頁面呢? 我是否需要使用其他任何功能來重定向? 還是我的代碼中有任何錯誤?
您應該只編碼值,而不是整個URL。
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-這里應該有特殊字符
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.