Using external data resources
Reading resources via HTTP
There are different ways to load a resource. The method that is
compatible with most browsers is XMLHttpRequest
:
Note, however, that this method does not work for accessing an HTML
file via file://
as detailed in a
separate article.
You can use additional events of
XMLHttpRequest
such as error
and
progress
.
Connection error reporting
The error event is called if there is a networking error, for example
a connection loss during loading. Note that a Not found
HTTP
response is not handled by the error
event. Instead, it
must be handled manually using the request status
as
shown above in the load
event listener.
Progress reporting
Progress events allow you to observe the loading process, which is interesting for large resources and slow network connections.
Writing resources via HTTP
The following example uses a HTTP PUT request to create/change data on disk. As this is a security risk, Kontrast HTTP server blocks PUT requests by default (and most HTTP servers block them in general). Please refer to the Kontrast HTTP server documentation for details on how to configure Kontrast HTTP server to allow PUT requests for certain directories.
Large binary data sets (such as typed arrays, e.g.
Float64Array
) are best written as a Blob
.