0

i'm writing a project with angular and springboot.

I got the problem. when i click the submit button ,angular should send a post request and the application should print "post api working!!!"

But it's not works,the application print nothing.

my api code as belows: enter image description here

i use the formdata to get inputdata,and my angular post request: enter image description here

enter image description here

CAN ANYONE TELL ME WHAT AM I DOING WORONG? THANKS!

RainOnMe77
  • 145
  • 1
  • 1
  • 6
  • Check the network tab for api calling. It maybe possible that your java application is not allowing angular app to make requests i.e., CORS origin issue for requests from port 4200 to 8080 – Beshambher Chaukhwan Feb 23 '21 at 03:15
  • **CORS origin issue** https://stackoverflow.com/questions/32319396/cors-with-spring-boot-and-angularjs-not-working/32320294#32320294 – Murugan Feb 23 '21 at 05:16

1 Answers1

0

If you have a problem with CORS add this code to you Bootsrap class

@Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedOrigins("http://localhost:4200" or different address) 
                        .allowedMethods("PUT", "DELETE", "GET", "POST");
            }
        };
    }

But as I understand it, judging by the console, the error is not in CORS. Check the mappings, maybe the endpoint is incorrect? Maybe you have @RequestMapping above your Java class?

Why are there no errors in the console at all if the program does not work?

erst_dev
  • 189
  • 1
  • 8