Source Code

for file S02_AJAXCoreSamples/CalcFactorsAJAX.htm

<!DOCTYPE html>
<html lang="en">

<head>
  <title>Prime factors calculator using AJAX actions</title>
  <link href="/mathertel.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="/ajaxcore/ajax.js"></script>
  <script type="text/javascript" src="/ajaxcore/GetJavaScriptProxy.aspx?service=/AJAXEngine/S02_AJAXCoreSamples/CalcService.asmx"></script>
  <!--
  // CalcFactorsAJAX.htm
  // Sample showing the usage of AJAX Actions.
  // Copyright (c) by Matthias Hertel, http://www.mathertel.de
  // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
  // -----
  // 18.11.2005 minor fix in layout.
-->
</head>

<body>
  <a style="position: absolute; right: 32px; top: 10px" href="../ViewSrc.aspx">View Source</a>
  <h1>Prime factors calculator using AJAX actions</h1>
  <table style="table-layout: fixed; width: 620px">
    <tbody>
      <tr>
        <th><label for="inputField">Please enter a number:</label></th>
        <td><input id="inputField" onkeyup="ajax.Start(action1)"></td>
        <td style="padding-left: 12px">
          <button onclick="proxies.EnableCache(proxies.CalcService.CalcPrimeFactors)">enable
            caching</button></td>
      </tr>
      <tr>
        <th><label>The factors are:</label></th>
        <td colspan="2"><input id="outputField" size="60" disabled="disabled"></td>
      </tr>
    </tbody>
  </table>
  <script defer="defer" type="text/javascript">

// to set up a debug output in an alert box use:
// proxies.CalcService.CalcPrimeFactors.corefunc = proxies.alertResult;

// to set up a debug output of the http response body in an alert box use:
// proxies.CalcService.CalcPrimeFactors.corefunc = proxies.alertResponseText;

// attach window.alert for displaying result to make the direct webservice call asynchronous
// proxies.CalcService.CalcPrimeFactors.func = window.alert;

// alert any exceptions...
// proxies.CalcService.CalcPrimeFactors.onException = proxies.alertException;


// declare an AJAX action
var action1 = {
  delay: 200,
  prepare: function() { return (document.getElementById("inputField").value); },
  call: proxies.CalcService.CalcPrimeFactors,
  finish: function (p) { document.getElementById("outputField").value = p; },
  onException: proxies.alertException
} // action1

  </script>
  <hr />
  <h3>Hint:</h3>
  <p>try 12313123123123 or 12313123123123123123 for long running calculations ! </p>
  <hr />
  <p>This sample uses HTML, Javascript and the XMLHTTP object on the client to call
    a WebService.</p>
  <p>This page is part of the <a href="http://www.mathertel.de/AJAXEngine/">Aspects
    of AJAX</a> project.</p>
  <p>For updates and discussions see <a href="http://ajaxaspects.blogspot.com/">http://ajaxaspects.blogspot.com/</a>.</p>
  <hr />
</body>
</html>


This page is part of the http://www.mathertel.de/ web site.

For updates and discussions see http://ajaxaspects.blogspot.com/.