简体   繁体   中英

Proper way to send GET parameters via AngularJS

In AngularJS, a GET request can be done by using:

$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.

My question is, that name may contain character like '&'. How to encode such characters when sending data via angular ?

Like given in the above comment, encodeURIComponent will work. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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