I've been trying to do a basic experiment with Spring Boot: To consume my own REST endpoint from a basic html file.
On the one hand, my SpringBoot endpoint cannot be simpler (and it's working fine btw):
@RestController
@EnableAutoConfiguration
public class Pru {
@RequestMapping("/hello")
String hello() {
return "hello world!";
}
}
I am sure that the problem has to be in the AJAX call, but I cannot find what's wrong with it after investigating it. Maybe I am lacking any config?
$.ajax({
type: "GET",
url: "/hello",
success: function (data) {
alert("Success!");
alert("Received Data: "+data);
},
error: function (response) {
alert("Error: "+response)
}
});
EDIT: Please note this is not a duplicate. I am just trying to set a minimal SpringBoot working example about consuming my own endpoints. CORS is appearing here too, but it's not the root of the problem. I don't want to know how to solve CORS, I just want to know how to make a basic endpoint that can be consumed from AJAX.