Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

103
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda