HTML and CSS Reference
In-Depth Information
if (result == true) {
$("#status").html("You are Online!");
$("#submit").removeAttr('disabled');
setTimeout(CheckOnline, 5000);
}
},
error: function () {
$("#status").html("You are Ofline!");
$("#submit").attr('disabled', 'disabled');
setTimeout(CheckOnline, 5000);
}
});
}
This code should look familiar: you used a similar technique in the Clock application. Using the
setTimeout() method, you call CheckOnline() every five seconds. CheckOnline() then calls the IsOnline()
controller action method. If this call is successful, it indicates that a network connection is available;
otherwise, the network is unavailable. Accordingly, the Submit Answers button is enabled or disabled by
adding or removing the disabled attribute. IsOnline() is shown in Listing 8-15.
Listing 8-15. IsOnline() Action Methodpublic JsonResult IsOnline()
{
return Json(true);
}
IsOnline() returns true in JSON format. You can now run the Survey application and test it by
stopping the application in IIS Express, as explained earlier.
Summary
Most web applications need a live network connection to the web server in order to function properly.
Such applications involve heavy interaction between client and server. Some web applications, however,
can work without an active network connection to the web server. Such applications usually involve heavy
client-side functionality. HTML5 allows you to develop such offline applications easily. Not every
application is a good candidate, but if the need arises, you have native support for such offline
applications.
At the heart of an offline application is a cache manifest file that lists all the files that are needed in
offline mode. If required, an offline application can connect with the web server when a network
connection is available and transfer data or execute server-side code. The applicationCache object
introduced in HTML5 represents an offline application cache and helps you to track various application
life cycle events by raising events.
HTML5 adds rich client-side capabilities to your web applications. Another such area is client-side file
access. Traditionally, JavaScript couldn't access local files in any manner. The HTML5 File API provides a
standardized way to deal with local files. The next chapter discusses this feature in detail.
 
Search WWH ::




Custom Search