Javascript 如何对url进行编码以获取$resource中的请求?

Javascript 如何对url进行编码以获取$resource中的请求?,javascript,angularjs,Javascript,Angularjs,以下是我在控制器内的功能: event.preventDefault(); url=event.target.href; var data=productionService.getUrl().get({ urlvalue:encodeURIComponent(url) }, function(success){ window.open(success,'_blank'

以下是我在控制器内的功能:

      event.preventDefault();
      url=event.target.href;                        
      var data=productionService.getUrl().get({
        urlvalue:encodeURIComponent(url)
      }, function(success){
        window.open(success,'_blank');
      }, function(error){
        alert("error:"+JSON.stringify(error))
      });
    } else {
      window.open(url,'_blank');
    }
  }
}
在工厂内:

getUrl:function(){
  return $resource("requesturl?id=:urlvalue");
}
单击url时发生404错误,并且该url具有http%25。。。代替http://
我可以做些什么来修复此错误。

这是因为您按照中的示例使用了encodeURIComponent

res的结果将是:

http%3A%2F%2Fw3schools.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab
你想要的是

getUrl:function(){
 return $resource(encodeURIComponent("requesturl?id=:urlvalue"));
}

为什么有http%25?这在警报错误中显示,它必须是http://这是我无法确定的…%252F03…%252404NotFound显示在浏览器控制台中。我已经删除了其中的一些值。。。。对于机密性HTTP%3A%2F%2F,请尝试此操作。我正在将url作为参数发送。url包含。。当发出请求时,会发生错误,在浏览器控制台我看到url被转换为http%25。。。我使用了encodeurlcomponent,但这没有帮助
getUrl:function(){
 return $resource(encodeURIComponent("requesturl?id=:urlvalue"));
}