Search the Community
Showing results for tags 'xmlhttprequest'.
Found 2 results
There are afaik 3 ways to read external files directly from the client : using ajax / xmlhttprequest using the filereader using the fetch api 1: get xmlhttprequest var FHttp := TW3HttpRequest.Create; FHttp.OnDataReady := lambda writeln(FHttp.responsetext); end; FHttp.open('GET','res/textfile.txt'); FHttp.send(); 2: file input W3EditBox1.InputType := itFile; W3EditBox1.Handle.ReadyExecute( procedure () begin W3EditBox1.OnChanged := procedure(sender:TObject) begin var reader: variant; asm @reader = new FileReader(); end; reader.onload := lambda writeln(reader.result); end; reader.readAsText(W3EditBox1.handle.files); end; end); 3: fetch api var window external 'window': variant; window.fetch('res/textfile.txt') .then(function(response:variant):variant begin result := response.text(); end) .then(procedure(myText:variant) begin writeln(myText); end); these fetch calls return a promise and the promise returns a response The fetch api is a mechanism which can replace the usual ajax calls. This api is primarily designed to act on network events. (see this post), but works for simple file fetching as well 4: Variations of the above, see f.i. this one using webworkers var FileReader : variant := new JObject; asm @FileReader = new Worker('filereader.js'); end; FileReader.onmessage := procedure(e: variant) begin writeln(e.data); end; FileReader.postMessage('res/textfile.txt'); //read file through webworker (filereader.js) demo / project (demo output is to console : ctrl+shift+i)
I'm wanting to create a very simple NodeJS server that filters/forwards JSON request and responses. Currently I have my SmartMobileStudio built web application using unit W3C.XMLHttpRequest to talk directly to a JSON REST store, but I want to insert this a server between these. I thought it was going to be a simple matter of reusing W3C.XMLHttpRequest, however it seems I shouldn't use this class since it is W3C - meaning web browser only? Do I need a NodeJS.XMLHttpRequest unit? Unfortunately my research has found that NodeJS doesn't support that XMLHttpRequest out of the box but does via the following package: https://www.npmjs.com/package/xmlhttprequest How would I best be to go about trying to get this working? Thanks in advance.