Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
spring mvc ajax get work but post not work when i send request to remote server from localhost
  $(".submit").click(function (e) {
    e.preventDefault();
    $.ajax({
      async: true,
      crossDomain: true,
      method: "post",
      data: $("form[name=something]").serialize(),
      url: "myUrl",
      success: function (res) {
        console.log(res);
      },
      error: function (res) {
        console.log(res.status);
      },
    });
  });

and my spring mvc controller like

@RestController
@CrossOrigin(origins = {"*"},
        methods = {RequestMethod.GET, RequestMethod.POST,
            RequestMethod.PUT, RequestMethod.DELETE})
public class AppController {
...
...
...
}

If is send (get) request it work properly but when i send (post) it got exception : Access to XMLHttpRequest at (remote server)from origin (localhost)has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Make sure the CORS policy is opened at the remote domain. if not, you will get the same error. Also if you are using Spring and created/extended a WebSecurityConfigurerAdapter file, you can configure the CORS by redefining CorsConfigurationSource bean in the WebSecurityConfig file. just make sure to add your localhost url in allowed origins.

Something like below:

@Bean
  public CorsConfigurationSource corsConfigurationSource() {
    final CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowedOrigins(ImmutableList.of("..your localhost url.."));
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", configuration);
    return source;
  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!