angularjs资源斜线参数 [英] angularjs resource slash parameters
问题描述
我正在使用$ resource进行rest api调用.我对该资源的呼叫就像这样:
I am using $resource to make a rest api call. My call to that resource is like that :
Client.get({parametres : param}
我的问题是参数包含"\"字符,使调用失败,并通过
My problem is that param contains "\" character, that make the call fail with
400错误的请求
400 Bad Request
响应.
如何转义"\"字符?
谢谢.
推荐答案
encodeURIComponent
应该可以解决问题.
encodeURIComponent()方法通过用表示字符的UTF-8编码的一个,两个,三个或四个转义序列替换某些字符的每个实例来编码统一资源标识符(URI)组件(只会是四个转义)由两个替代"字符组成的字符序列.
The encodeURIComponent() method encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).
按照: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
Client.get({ parameters: encodeURIComponent(param) }
这篇关于angularjs资源斜线参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!