2017-01-23 72 views
1

我希望將整個字符串'/image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1'作爲參數actiondownloadsingle.htm如何使用javascript傳遞url地址字符串作爲url的參數?

而我嘗試使用encodeURI函數來編碼字符串,但我失敗了,我無法在服務器客戶端中獲取參數origurl的正確值,我該怎麼辦?謝謝!

$('.CssDownloadSingle').click(function() { 
    var fileName = GetHiddenFilename(this); 

    var origurl ='/image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1' 

    location.href = "actiondownloadsingle.htm?origurl=" +encodeURI(origurl); 
}); 
+1

你的問題回答[這裏](http://stackoverflow.com/questions/1737935/ JavaScript的是什麼 - 是最推薦的路到通網址-AS-URL參數)。 快捷方式:使用encodeURIComponent() –

回答

1

嘗試使用encodeURIComponent將其編碼爲參數的值:

var origurl ='/image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1'; 
 

 
alert(
 
    "encodeURIComponent: actiondownloadsingle.htm?origurl=" + encodeURIComponent(origurl) + "\r\n" 
 
    + "encodeURI:      actiondownloadsingle.htm?origurl=" + encodeURI(origurl) 
 
);

+0

謝謝!當我在服務器客戶端中使用Java時,如何解碼值? – HelloCW

+0

從_GET讀取時,您應該已經解碼了。不太瞭解Java後端 – Justinas