Error 503 "No 'Access-Control-Allow-Origin' header" [closed]

2

I'm trying to make a connection in datasnap using ajax

My code:

                var url = 'http://cloud.nooven.com.br:12345/datasnap/rest/TServerMethods1/CriaSessao/'+cpfCnpj+'|'+usuario+'|'+senha;
                console.log(url);
                $.ajax({
                    type: "GET",
                    url: url,
                    dataType: "json",
                    success: function(data){
                        console.log('sucesso');
                    },
                    error: function(data){
                        console.log('erro');
                    }
                });

the page .html that is accessing ta on the server, so it is as localhost in the variable url , the error that occurs is this:

XMLHttpRequest cannot load http://cloud.nooven.com.br:12345/datasnap/rest/TServerMethods1/CriaSessao/68243096000152%7CMOACIR%7C123456. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://cloud.nooven.com.br' is therefore not allowed access. The response had HTTP status code 503.

Thank you.

    
asked by anonymous 03.07.2015 / 20:33

1 answer

1

According to this link CORS on DataSnap REST Server you should use this way: / p>

procedure TWebModule1.WebModuleBeforeDispatch(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  //Permite requisições de diferentes dominios
  Response.SetCustomHeader('Access-Control-Allow-Origin','*');
  if FServerFunctionInvokerAction <> nil then
    FServerFunctionInvokerAction.Enabled := AllowServerFunctionInvoker;
end;
    
03.07.2015 / 20:53