简体   繁体   中英

How can i pass special character like “#”, “^” in http.post url as parameters

While passing special characters like # , ^ in http.post url , it is returning as bad request.

$http.post("requestFormDataInsert.jsp?manager=" +$scope.managerName+ "&productName="+ $scope.productName+ "&productVersion="+ $scope.versionNumber+ "&expectedDate="+ $("#datepicker1").val()+  "&description=" +$scope.description+ "&requestType="+$scope.requestType ).then( function( resp ){
    $scope.requestId = resp.data;
    alert("Your response has been updated successfully")
    $location.path('/');
});

Suppose we have some parameters here which contains as # (hash) or ^ characters so it is telling as bad request .

You need to encode your params. You can encode them manually by using encodeURI or just add them into the param section on your request. In that way your params get serialized and encoded automatically.

$http({
  url: 'requestFormDataInsert.jsp',
  method: 'POST',
  params: {
    manager: $scope.managerName,
    productName: $scope.productName,
    productVersion: $scope.versionNumber,
    expectedDate: $("#datepicker1").val(),
    description: $scope.description,
    requestType: $scope.requestType
  }
}).then(function (result) {
});

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