-1
I am sending a request by ajax to my REST server and am getting back:
Access to Xmlhttprequest at 'http://localhost:8081/datasnap/Rest/Tcadastros/Group/' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.
Along with:
OPTIONS http://localhost:8081/datasnap/Rest/Tcadastros/Group/ 500 (Internal Server Error)
Can someone give me a little light on how to fix it? I understand that the problem is probably in the source header (Access-Control-Allow-Origin) but I don’t know how to pass it or if the problem is in the client side or server side.
My ajax is like this:
$(document).on('click', "#modalgravar", function(){
var Ecdgrupo = $("#Cdgrupoedit").val();
var Egrupo = $("#grupoedit").val();
var eData = {"Cdgrupo": Ecdgrupo, "Grupos": Egrupo};
var eURL = "http://localhost:8081/datasnap/rest/TCadastros/Grupo/"
alert(JSON.stringify(eData));
$.ajax({
type:"PUT",
url: eURL,
crossDomain : true,
data: JSON.stringify(eData),
contentType:"application/json",
headers:{'Access-Control-Allow-Origin': '*'},
success: function(){
alert("Editado!");
},
error: function(){
alert("ERRO: O grupo não foi editado!");
},
});
});
When I try to make the call in Internet Explorer it works perfectly, just like using Postman. But on Chrome and firefox it gives me these errors.
What is the language of the backend guy ? php, c#, nodejs ??
– Joan Marcos