Я собираюсь отправить данные из AngularJS, чтобы использовать их позже в бэкэнде Python + Java. Проблема в том, что он отправляется как нулевой, и я не могу понять, почему. В консоли google chrome нет ошибок, но я вижу проблему в консоли моего java сервера (mvn -P dev), где я использую return, чтобы узнать значение переменной при поступлении:
DEBUG 13496 --- [XNIO-23 task-27] a. c .psaop.logging.LoggingAspect: Выход: us.com.generi c .web.rest.DataController.getData () с результатом = переменная 'null' была сохранена
Контроллер Java, получающий информацию от AngularJS:
@RestController
@RequestMapping("/api")
public class DataController {
@RequestMapping("/data/")
@ResponseStatus(code = HttpStatus.OK)
public @ResponseBody String getData( @RequestParam(name="dataVariable", required=false) String dataVariable) {
return "The variable '" + dataVariable + "' was saved";
}
}
Angular JS Контроллер:
angular
.module('Generic')
.controller('DataController', DataController);
DataController.$inject = ['$scope', '$http', 'URI', '$timeout'];
function DataController ($scope, $http, URI, $timeout) {
var myInformation = 'HeadStreet';
$http.post(URI + 'api/data/', {
dataVariable: myInformation
}, {
withCredentials: true,
headers: {
'Content-Type': 'charset=utf-8'
}
}).then(Success, Error);
}
function Success() {
alert('Variable sent');
}
function Error() {
alert('Issue while sending data');
}
}