0
我向服務器發送POST請求。作爲響應,服務器發送一個http代碼和一個純文本。Angularjs解析非JSON POST響應
return Response.status(200).entity("Started").build();
AngularJS嘗試解析爲JSON響應,我得到一個解析錯誤
Error: JSON.parse: unexpected character at line 1 column 1 of the JSON data
這是我的角碼
$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)
});
}
Thanx,工作完美。只是一個小的語法錯誤,]缺少 – user567
@ user567好消息,並對語法錯誤感到抱歉 –