mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-05 07:48:59 +02:00
35 lines
697 B
ObjectPascal
35 lines
697 B
ObjectPascal
program tryfetch;
|
|
|
|
{$mode objfpc}
|
|
|
|
uses
|
|
browserconsole, JS, Web, SysUtils;
|
|
|
|
procedure myFetch; async;
|
|
var
|
|
response: TJSResponse;
|
|
myBlob: TJSBlob;
|
|
image: TJSHTMLImageElement;
|
|
objectURL: string;
|
|
begin
|
|
try
|
|
response := await(window.fetch('pas2js.png'));
|
|
|
|
if not response.ok then
|
|
raise Exception.Create('HTTP error! status: '+str(response.status))
|
|
else begin
|
|
myBlob := await(response.blob());
|
|
objectURL := TJSURL.createObjectURL(myBlob);
|
|
image := TJSHTMLImageElement(document.createElement('img'));
|
|
image.src := objectURL;
|
|
document.body.appendChild(image);
|
|
end;
|
|
except
|
|
console.log(JSExceptValue);
|
|
end;
|
|
end;
|
|
|
|
begin
|
|
myFetch;
|
|
end.
|