0

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.

dev
  • 506
  • 6
  • 16
  • Possible duplicate of [CORS with spring-boot and angularjs not working](https://stackoverflow.com/questions/32319396/cors-with-spring-boot-and-angularjs-not-working) – Shota Apr 02 '18 at 09:04
  • I fully disagree with you @Shota, the example is completely different, using a different approach, structure and annotations. – dev Apr 02 '18 at 09:05

0 Answers0