<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Chapter 6 : Networking Considerations - Data Error Explorer</title>
<link rel="stylesheet" href="https://ajaxref.com/ch6/global.css" type="text/css" media="screen" />
<script src="https://ajaxref.com/ch6/ajaxtcr.js" type="text/javascript">
<script type="text/javascript">
function showSuccess(response)
{
var responseOutput = document.getElementById("responseOutput");
if (response.xhr.responseXML.getElementsByTagName("requestip").length > 0)
{
var requestip = response.xhr.responseXML.getElementsByTagName("requestip")[0].firstChild.nodeValue;
var serverdate = response.xhr.responseXML.getElementsByTagName("serverdate")[0].firstChild.nodeValue;
var message = "Hello World to user from " + requestip + " at " + serverdate;
responseOutput.innerHTML = "Request id: "+response.requestID+ " - <strong>SUCCESS:</strong> " + message;
}
else
showFail(response, "Cannot read packet: expected XML nodes not found");
}
function showFail(response, errorMessage)
{
var responseOutput = document.getElementById("responseOutput");
responseOutput.innerHTML = "Request id: "+response.requestID+ " - <strong style='color:red'>FAIL: </strong> " + errorMessage;
}
function showProgress(request)
{
var responseOutput = document.getElementById("responseOutput");
responseOutput.innerHTML = "Request id: "+request.requestID+ " - Sent ( " + request.timespent + " )";
}
function sendRequests(form)
{
var responseOutput = document.getElementById("responseOutput");
responseOutput.innerHTML = "";
var error = form.error.options[form.error.selectedIndex].text;
var payloadString = "delay=3&xmlerror=" + AjaxTCR.data.encodeValue(error);
var url = "https://ajaxref.com/ch6/networkexplorer.php";
var options = { method: "GET",
onSuccess : showSuccess,
onFail : showFail,
payload: payloadString,
showProgress: true,
onProgress: showProgress,
responseContentType: "text/xml"
};
var theRequest = AjaxTCR.comm.sendRequest(url,options);
if (theRequest)
responseOutput.innerHTML = "Request id: "+theRequest.requestID+ " - Sent ";
}
window.onload = function ()
{
document.requestForm.requestButton.onclick = function () { sendRequests(this.form); };
};
</head>
<body>
<div id="mainpage">
<div class="content">
<h1>Data Error Explorer</h1>
<form action="#" name="requestForm">
<fieldset>
<table width="100%">
<tr class="row">
<td width="100">Error: </td>
<td><select name="error">
<option>None</option>
<option>Wrong Content</option>
<option>Wrong Content Type</option>
<option>Malformed XML</option>
</select></td></tr>
</table>
</fieldset>
<br />
<input type="button" name="requestButton" value="Send Request" />
</form>
<br />
</div></div>
<div class="response">
<div id="responseOutput"></div>
</div>
</body>
</html>