5.3. Using RequestManager
To try out the RequestManager object, it's easiest to set up a page that sends multiple requests in a row and reports back when the results have been received. In this way, the order in which the responses are received indicates the order in which the requests were sent (with a small margin of error due to different server response times per request). Consider the following simple HTML page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Request Manager Example</title>
<script type="text/javascript" src="PriorityQueue.js"></script>
<script type="text/javascript" src="RequestManager.js"></script>
<script type="text/javascript" src="RequestManagerExample.js"></script>
</head>
<body>
<fieldset>
<legend>Responses</legend>
<div id="divResponses"></div>
</fieldset>
</body>
</html>
This page includes the necessary RequestManager files and has a <fieldset/> surrounding a <div/> called "divResponses". This <div/> element is responsible for outputting the results of each request so that it's obvious as to what has occurred. The RequestManagerExample.js file contains the JavaScript for this example, beginning with some callback functions to handle various responses:
function outputResult(oResponse, sColor) { var divResponses = document.getElementById("divResponses"); var oRequest = oResponse.request; var sMessage = "<div style=\"background-color:" ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access