Solicitud de origen cruzado Servicio REST de Spring bloqueado + AJAX
No se puede llamar al servicio REST de primavera
Mi servicio de primavera
@RequestMapping(value = "/MAS/authenticate", method = RequestMethod.POST)
public ResponseEntity<Map<String, String>> authenticate(@RequestBody Subject subject) {
Map<String, String> result = new HashMap<String, String>();
result.put("result_detail", "Invalid Password");
result.put("result", "failure");
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
responseHeaders.add("Access-Control-Allow-Origin", "*"); // also added header to allow cross domain request for any domain
return new ResponseEntity<Map<String, String>>(result, responseHeaders, HttpStatus.OK);
}
Mi código AJAX
$.ajax(
{
crossDomain: true,
type: "POST",
contentType: "application/json; charset=utf-8",
async: false,
url: "http://localhost:8080/SpringMVC/rest/MAS/authenticate",
headers: {"Access-Control-Allow-Origin" : "*"},
data:{},
dataType: "json", //also tried "jsonp"
success: function(data, status, jqXHR)
{
alert('success');
},
error: function(jqXHR, status)
{
alert('error');
}
});
Recibo el siguiente error :(
Solicitud de origen cruzado bloqueada: la misma política de origen no permite leer el recurso remoto enhttp: // localhost: 8080 / SpringMVC / rest / MAS / authenticate. Esto se puede solucionar moviendo el recurso al mismo dominio o habilitando CORS.
También he intentadodataType: "jsonp"
. agrega mi objeto del cuerpo a la URL que hace una URL diferente y no puede golpear la URL de mi servicio y obtuvo un error 404.
Mi navegador: firefox 36.0.4
¿Cómo puedo deshacerme de este error, alguna ayuda?