Click here to Skip to main content
12,890,181 members (42,447 online)
Click here to Skip to main content
Articles » Languages » XML » Web Services » Downloads


82 bookmarked
Posted 5 Jul 2005

A proxy generator to WebServices for JavaScript and AJAX

, 20 Sep 2005
Calling a server from JavaScript is a fundamental part of AJAX applications. Using WebServices with SOAP and WSDL is easy if proxy objects and methods are available in the browser.

  <title>Prime factors calculator using AJAX</title>
  <script type="text/javascript" src="ajax.js"></script>
  <script type="text/javascript" src="GetJavaScriptProxy.aspx?service=CalcService.asmx"></script>

  <h1>Prime factors calculator</h1>
        <th><label for="inputField">Please enter a number:</label></th>
          <input id="inputField" onkeyup="ajax.Start(action1)"></td>
        <td style="padding-left: 12px">
          <button onclick="proxies.EnableCache(proxies.CalcService.CalcPrimeFactors)">enable caching</button></td>
        <th><label>The factors are:</label></th>
          <input id="outputField" size="60" disabled="disabled"></td>
  <p>try 12313123123123 or 12313123123123123123 for long running calculations ! </p>
  <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: ajax.alertException
} // action1

  <hr />
  <p>This sample uses the AJAX Engine on the client to call a WebService that calculates the prime numbers
    of a given number.</p>
  <p>This page is part of the <a href=""></a>
  <hr />


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Matthias Hertel
Architect Deutsche Bank AG
Germany Germany

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 20 Sep 2005
Article Copyright 2005 by Matthias Hertel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid