如何使用javascript传递url地址字符串作为url的参数?

时间:2017-01-23 07:59:03

标签: javascript jquery

我希望将整个字符串'/image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1'作为actiondownloadsingle.htm的参数传递。

我尝试使用函数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 个答案:

答案 0 :(得分: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)
);