ajax.pas 824 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. unit ajax;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, Web;
  6. type
  7. { TAjax }
  8. TAjax = class
  9. private
  10. FOnLoad: TJSEventHandler;
  11. FXmlHttpRequest: TJSXMLHttpRequest;
  12. procedure SetOnLoad(AValue: TJSEventHandler);
  13. public
  14. constructor Create;
  15. destructor Destroy; override;
  16. procedure Open(AMethod, AUrl: string);
  17. property OnLoad: TJSEventHandler write SetOnLoad;
  18. end;
  19. implementation
  20. { TAjax }
  21. procedure TAjax.SetOnLoad(AValue: TJSEventHandler);
  22. begin
  23. FXmlHttpRequest.addEventListener('load', AValue);
  24. end;
  25. constructor TAjax.Create;
  26. begin
  27. FXmlHttpRequest := TJSXMLHttpRequest.new;
  28. end;
  29. destructor TAjax.Destroy;
  30. begin
  31. // FXmlHttpRequest.Free;
  32. end;
  33. procedure TAjax.Open(AMethod, AUrl: string);
  34. begin
  35. FXmlHttpRequest.open(AMethod, AUrl, true);
  36. FXmlHttpRequest.send;
  37. end;
  38. end.