-2
我正在从angularjs 1.5x客户端向Java HTTP方法发送获取请求,并在客户端I将打印包含一些JSON数据的响应。当我使用“response.data”来打印JSON数据时,它只打印出整个响应而不是JSON
// method from an angular service that sends ajax requests
this.getTask = function(taskName) {
var url = 'http://localhost:9998/tasks/' + taskName;
var config = {
headers: {
'Content-Type': 'application/json'
}
};
$http.get(url, config)
.then(function successCallback(response) {
console.log(response.data);
}, function errorCallback(response) {
console.log(response);
});
};
请求成功执行,但在声明中response.data
不返回JSON数据,但它而不是返回这一点;
Object { data: Object, status: 302, headers: headersGetter/<(), config: Object, statusText: "Found" }
通常这种说法会打印出包含在上述对象中的数据对象。出了什么问题?
我的猜测是它没有使用successCallback,而是使用errorCallback打印出响应。尝试调整你的代码看起来像'then(function(response){console.log(response.data))。catch(function(err){console.error(err)});' – thibmaek