2017-01-23 9 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のように推奨されるway-to-pass-urls-as-url-parameters) ショートカット: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

関連する問題