Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1
Online/Offline | 105

document.body.appendChild( elem );
}
</script>

</head>
<body onload="doLoad( )">

</body>
</html>

Online/Offline


Caching Assets for Offline Use


Problem


You want to load an asset from a URL and store it for use
when the application is offline.


Solution


Use the File I/O API to save the requested asset to the appli-
cation’s store and read that file on subsequent requests.


Discussion


In this example, we will load an XML file that is at a known
URL. Once the data has been loaded, it will be saved to the
local disk and on subsequent requests for the document, it
will be loaded from the local disk instead of from the remote
location.


First, we will use theXMLHttpRequestobject to load the XML
data from the remote location. TheXMLHTTPRequest.open( )
method takes three arguments. The first argument is the
method of the HTTP request that is being made. The second
argument is the URI of the location of the data being loaded.
The third argument is a Boolean that specifies whether the
operation will be asynchronous.

Free download pdf