I'm trying to send a simple array but it's not working. I just want to send all the array at the same time and read containerName and containerStatus.
My first console.log outputs this.
{"containerName":"123","containerStatus":"Up 2 hours"}{"containerName":"ingesdev","containerStatus":"Up 2 hours"}
Java
List<Container> runningContainers = dockerClient.listContainersCmd()
.exec();
JSONObject jsonContainer = new JSONObject();
for (Container container:runningContainers) {
jsonContainer.put("containerName", container.getNames()[0].replace("/",""));
jsonContainer.put("containerStatus",container.getStatus());
response.getWriter().write(jsonContainer.toString());
}
JavaScript
$.ajax({
type: 'post',
url: 'Containers',
success: function (result) {
console.log(result);
var container = container = JSON.parse(result);
console.log(container.containerName);
},
error: function() {
}
});
VM362:1 Uncaught SyntaxError: Unexpected token { in JSON at position 54 at JSON.parse () at Object.success (dashboard.js:10) at i (jquery.min.js:2) at Object.fireWith [as resolveWith] (jquery.min.js:2) at A (jquery.min.js:4) at XMLHttpRequest. (jquery.min.js:4)