我對我的下面的角碼感到有點沮喪,因爲它不會將JSON數據發送到我在同一臺機器上運行的基於spring boot的微服務。請幫助我!僅供參考,我是JavaScript世界的新手。
$scope.addBook = function() {
var data = $.param({
json: JSON.stringify({
name: $scope.bookName,
isbn: $scope.isbn,
author: $scope.authorName,
pages: $scope.pages
})
});
var config = {
headers : {
'Content-Type': 'application/json'
}
}
var result = $http.post('http://localhost:8080/book', data, config);
result.success(function (data, status, headers, config) {
$scope.result = JSON.stringify({data: data});
});
result.error(function (data, status, header, config) {
$scope.result = JSON.stringify({data: data});
});
};
你得到的錯誤是什麼? –
你在控制檯中得到什麼?你在哪裏得到錯誤?你能夠在成功回調後訪問成功數據嗎? –