js传递参数中包含+号时的处理方法

时间:2021-11-24 12:57:36

encodeURI(url).replace(/\+/g, '%2B')

例子:

$scope.getAnesthesiawaystatistical = function (annual, anesthesiaMethodRep) {
var Anesthesiurl = "/api/v1/AnesthesiAwayStatistical/GetAnesthesiAwayStatisticalCount?anesthesiaMethodRep=" + "'" + anesthesiaMethodRep + "'" + "&annual=" + annual;
alert(encodeURI(Anesthesiurl).replace(/\+/g, '%2B'));
$http.get(encodeURI(Anesthesiurl).replace(/\+/g, '%2B')).success(function (data) {

if (data.has_val) {
$scope.AnesthesiAwayStatisticalList = data.result;

console.log($scope.AnesthesiAwayStatisticalList);
}
});
}