Source Code

for file S01_AsyncSamples/CalcFactorsServer1.htm

<!DOCTYPE html>
<html lang="en">
  <meta name="vs_targetSchema" content="">
  <title>Prime factors calculator using a WebService</title>
  <a style="position: absolute; right: 32px; top: 10px" href="../ViewSrc.aspx">View Source</a>
  <h1>Prime factors calculator using a normal server page</h1>
        <th><label for="inputField">Please enter a number:</label></th>
        <td><input id="inputField" onkeyup="StartCalcPrimeFactors()"></td>
        <th><label for="outputField">The factors are:</label></th>
        <td><input id="outputField" size="60" disabled="disabled"></td>
  <p>try 12313123123123 or 12313123123123123123 for long running calculations ! </p>

  <script type="text/javascript">
var _num = "";
var _timer = null;

function StartCalcPrimeFactors() {
  var inputText = document.getElementById("inputField").value;
  if (_num != inputText) {
    if (_timer != null)
    document.getElementById("outputField").value = "wait...";
    _num = inputText;
    _timer = window.setTimeout(CalcPrimeFactors, 300, "javascript");
  } // if

// calc prime factors
function CalcPrimeFactors() {
  var inputText, outputText;

  inputText = document.getElementById("inputField").value;

  if ((inputText == null) || (inputText.length == 0) || (inputText == "0"))

  var xmlObj = null;
  if (window.XMLHttpRequest){ 
    // If IE7, Mozilla, Safari, etc: Use native object
    xmlObj = new XMLHttpRequest()
  } else if (window.ActiveXObject) {
    // ...otherwise, use the ActiveX control for IE5.x and IE6
    xmlObj = new ActiveXObject("Microsoft.XMLHTTP"); 
  } // if"GET", "CalcFactorsRequest.aspx?number=" + inputText, false);
  outputText = xmlObj.responseText;

  document.getElementById("outputField").value = outputText;
} // CalcPrimeFactors


  <hr />
  <p>This sample uses HTML, Javascript and the XMLHTTP object on the client to call
    a WebService.</p>
  <p>A sychronous call is used so the client gets blocked when the server needs a long
    time or is not responding.</p>
  <hr />
    This page is part of the <a href="">Aspects of AJAX</a> project.</p>
    For updates and discussions see <a href=""></a>.</p>
  <hr />

This page is part of the web site.

For updates and discussions see