[Pas2js] TJSXMLHttpRequest questions
Ryan Joseph
ryan at thealchemistguild.com
Sun May 20 10:59:37 CEST 2018
1) How are we intended to use TJSOnReadyStateChangeHandler? I thought the callback would take a parameter to the TJSXMLHttpRequest but it doesn’t. The JavaScript way seems to be a closure so we can access the request in the same scope but we obviously don’t have those in Pascal.
2) Not really Pascal related but why does HandleLoadedFile get called 3 times? I had to call abort manually to stop it once I got the text I wanted.
procedure HandleLoadedFile;
begin
if length(request.responseText) > 0 then
begin
writeln(request.responseText);
request.abort;
end;
end;
request := TJSXMLHttpRequest.new;
request.open('GET', ‘file.html');
request.onreadystatechange := TJSOnReadyStateChangeHandler(@HandleLoaded);
request.send;
Regards,
Ryan Joseph
More information about the Pas2js
mailing list