逃脱' /'在angularjs变量中

时间:2014-12-29 16:42:47

标签: javascript angularjs

我想知道如何在angularjs中转义/,以便我可以将其作为路径变量发送以调用restful服务。截至目前,每当我尝试发送一个路径变量值为/的网址时,我就会收到404;即使我编码它也不起作用。

例如

  

http://monish.home.com/payment/9a2c1ae67d4ff85e561679fcff/credit/%252B8VMWj/YBC%252FNj3l/fetch/options

有没有办法可以编码并转义/

1 个答案:

答案 0 :(得分:0)

是的,它叫做encodeURIComponent

var a = 'http://monish.home.com/payment/9a2c1ae67d4ff85e561679fcff/credit/%252B8VMWj/YBC%252FNj3l/fetch/options'
encodeURIComponent(a); // result: "http%3A%2F%2Fmonish.home.com%2Fpayment%2F9a2c1ae67d4ff85e561679fcff%2Fcredit%2F%25252B8VMWj%2FYBC%25252FNj3l%2Ffetch%2Foptions"