CORS/AJAX with fpHTTPap Lazarus lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- automacaosamos · 2021-11-22 15:27 Could you help me with an example of an API using: fphttpapp, httpdefs, httproute, fpjson that implements CORS to receive AJAX requests ?? thanks ---------------------------------------------------------------------- Leledumbo · 2021-12-07 04:49 fpjson not required. CORS is implemented as a HTTP OPTIONS handler, so practically just: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Whatever(ARequest: TRequest; AResponse: TResponse);var  Origin: String;begin  if ARequest.Method = 'OPTIONS' then begin // handle CORS request    // normally, you would check the sent ORIGIN header, to see who sent the request    Origin := HttpRequest.GetCustomHeader('Origin');    // for instance, you only allow it from your own domain    if Origin = 'myowndomain.com' then begin      // send the header that allows it to request      AResponse.SetCustomHeader('Access-Control-Allow-Origin', Origin); // or if you allow it from anywhere, use '*' instead of Origin    end;  end;end; begin   HTTPRouter.RegisterRoute('/', @Whatever);end.