简体   繁体   English

通过AngularJS发送GET参数的正确方法

[英]Proper way to send GET parameters via AngularJS

In AngularJS, a GET request can be done by using: 在AngularJS中,可以使用以下命令完成GET请求:

$http({method:'GET', url:'', params:{:}}).success(function(data){ ... $ http({method:'GET',url:'',params:{:}})。success(function(data){...

Usually, in place of param value I use $form.name where name is a ng-model bounded to a text box. 通常,我使用$ form.name代替param值,其中name是绑定到文本框的ng模型。

My question is, that name may contain character like '&'. 我的问题是,该名称可能包含“&”之类的字符。 How to encode such characters when sending data via angular ? 通过angular发送数据时如何编码此类字符?

Like given in the above comment, encodeURIComponent will work. 就像上面的注释中给出的一样,encodeURIComponent将起作用。 But if you want to support old browsers also, you can easily do an encoding by yourselves. 但是,如果您还想支持旧的浏览器,则可以轻松地自己进行编码。 You can get all the URL Encoding Reference from W3schools. 您可以从W3schools获得所有URL编码参考。

http://www.w3schools.com/tags/ref_urlencode.asp http://www.w3schools.com/tags/ref_urlencode.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM