【发布时间】:2017-02-23 06:09:03
【问题描述】:
我向服务器发送一个 POST 请求。作为响应,服务器发送一个 http 代码和一个纯文本。
return Response.status(200).entity("Started").build();
AngularJS 尝试解析对 json 的响应,但出现解析错误
错误:JSON.parse:JSON 的第 1 行第 1 列出现意外字符 数据
这是我的 Angular 代码
$scope.submitForm = function() {
var url = 'http://localhost:8080/Server/server/start';
var request = $http({
method: 'POST',
url: url,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
return str.join('&');
},
data: {name: $scope.name}}).then(function(html) {
//success callback code
//console.log(html)
}, function(html) {
//error callback code
//console.log(html)
});
}
【问题讨论】: