I've done everything like in this tutorial: https://spring.io/guides/gs/consuming-rest-jquery/ This is my index.html:
<!DOCTYPE html>
<html>
<head>
<title>Hello jQuery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="hello.js"></script>
</head>
<body>
<div>
<p class="greeting-id">The ID is </p>
<p class="greeting-content">The content is </p>
</div>
</body>
</html>
And this is hello.js:
$(document).ready(function() {
$.ajax({
url: "http://localhost:8080/greeting"
}).then(function(data) {
$('.greeting-id').append(data.id);
$('.greeting-content').append(data.content);
});
});
Html and js files are on xampp on htdocs\rest folder, rest api works on intellij idea prebuild tomcat. This is result: picture 1
This is restult of rest api: picture 2
What did I wrong?
Edit: This is java spring boot code:
@RestController
public class GreatingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@CrossOrigin(origins = "http://localhost:8080")
@GetMapping("/greeting")
public Greeting greeting(@RequestParam(required = false, defaultValue = "World") String name) {
System.out.println("==== get greeting ====");
return new Greeting(counter.incrementAndGet(), String.format(template, name));
}
}