在 http.post url
中传递 #
、^
等特殊字符时,它会作为错误请求返回。
$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('/');
});
假设我们这里有一些参数,其中包含 #
(哈希)或 ^
字符,因此它表明错误请求
。
最佳答案
您需要对您的参数进行编码。您可以使用 encodeURI 手动对它们进行编码或者只是根据您的要求将它们添加到参数部分。这样你的参数就会自动序列化和编码。
$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) {
});
关于javascript - 我如何在 http.post url 中传递特殊字符,如 "#"、 "^"作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49315492/